This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################## | |
## A Function to Combine Estimates from MI | |
########################################## | |
comb.mi <- function(models) { | |
# Arguments | |
# models: a list of models, one estimated on each of m MI data sets. | |
# Note: I borrow the notation below mostly from Rubin's *Multiple Imputation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# log-likelihood for beta | |
ll.fn.beta <- function(theta, y) { | |
alpha <- theta[1] # optim() requires a single parameter vector | |
beta <- theta[2] | |
ll <- alpha*sum(log(y)) + beta*sum(log(1 - y)) - | |
length(y)*log(beta(alpha, beta)) | |
return(ll) | |
} | |
# function to estimate beta model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define log-likelihood function | |
ll.logit <- function(beta, y, X) { | |
p <- plogis(X%*%beta) | |
loglik <- sum(y*log(p)) + sum((1 - y)*log(1 - p)) | |
return(loglik) | |
} | |
# optimize | |
logit <- function(y, X) { | |
init.par <- rep(0, ncol(X)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load packages | |
library(foreign) # for read.dta() | |
library(arm) # for display() | |
# load data | |
fl <- read.dta("http://crain.co/am-files/data/fearon-laitin.dta") | |
# something weird is going on | |
table(fl$onset) # wtf? | |
fl$onset[fl$onset == 4] <- 1 # recode weird case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load libraries | |
library(arm) | |
# read data | |
d <- read.csv("http://crain.co/am-files/data/turnout-small.csv") | |
# estimate simple logit model | |
m <- glm(vote ~ educate + age + income, | |
family = binomial, data = d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load packages | |
library(MASS) | |
library(compactr) | |
library(compactr) | |
# read data | |
d <- read.csv("http://crain.co/am-files/data/hks.tab", sep = "\t") | |
keep <- c("osvAll", "troopLag", "policeLag", "militaryobserversLag", | |
"brv_AllLag", "osvAllLagDum", "incomp", "epduration", "lntpop", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replication of Hill, Moore, and Mukherjee (2013) | |
# load packages | |
library(arm) | |
# load data | |
d <- read.csv("http://crain.co/am-files/data/hmm.csv") | |
# examine data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d <- read.dta("http://crain.co/am-files/data/nes92.dta") | |
f <- vote ~ conservative + education + union + | |
income + black + distance_to_clinton + | |
distance_to_bush + economy_worse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install packages (if necessary) | |
install.packages("devtools") | |
install.packages("arm") | |
# install separation and compactr from GitHub | |
devtools::install_github("carlislerainey/compactr") | |
devtools::install_github("carlislerainey/separation") | |
# load packages | |
library(separation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <- 0 | |
k <- 0 | |
a <- c(1, 2, 3, 4, 5) | |
b <- c(1, 2, 3, 4, 5) | |
col <- 1:length(a) | |
names <- c("Carlisle", "B", "C", "D", "E") | |
plot(NULL, xlim = c(0, 1), ylim = c(0, 3), | |
xlab = expression(pi), |
OlderNewer