Hi Kosuke, all,
I just wanted to post a workaround/correct version of the code I
posted earlier, in case others run into the same problem. As Olivia
pointed out to me, zelig looks for the weights in the data.frame
passed to the "data" argument. But you need to give it the column name
of the weights, in quotes, to the "weights" argument. Thus, here is
some correct code:
library(Zelig)
data(turnout)
w <- rep(c(1,0), times = nrow(turnout)/2)
is.na(turnout$age) <- 1
## add the weights to your data.frame
turnout$ww <- w
## pass the name of the weights variable in the data.frame to "weights"
z.out1 <- zelig(vote ~ age, model = "logit", data = turnout, weights =
"ww")
## check that against the glm version:
g.out1 <- glm(vote ~ age, family = binomial(link = "logit"), data =
turnout, weights = w)
Now both zelig and glm run, with the same output. Hope that helps some folks.
Cheers,
matt.
On Tue, Apr 19, 2011 at 11:30 AM, Kosuke Imai <kimai(a)princeton.edu> wrote:
Unfortunately, Zelig only works with the data
frame without any missing data.
Kosuke
On Apr 14, 2011, at 1:45 PM, Matt Blackwell wrote:
Hi there,
I may have run into a problem with Zelig and the way it handles
weights with missing data. Here is a minimal working example of the
potential bug:
library(Zelig)
::snip::
##
## Zelig (Version 3.5-1, built: 2011-03-25)
::snip::
data(turnout)
## weights with missingness problem
w <- rep(1/nrow(turnout), times = nrow(turnout))
is.na(turnout$age) <- 1
## doesn't work
z.out1 <- zelig(vote ~ age, model = "logit", data = turnout, weights = w)
Error in model.frame.default(formula = vote ~ age, data = list(race = c(2L, :
variable lengths differ (found for '(weights)')
## works
g.out1 <- glm(vote ~ age, family=binomial(link="logit"), data =
+ turnout, weights=w)
The weights work when there is no missing data and zelig runs fine
with missing data and no weights. I'm on Ubuntu 10.04, but I've
replicated the same output on a Windows machine. Please let me know if
you need any more information.
Cheers,
matt.
~~~~~~~~~~~
Matthew Blackwell
PhD Candidate
Institute for Quantitative Social Science
Department of Government
Harvard University
url:
http://people.fas.harvard.edu/~blackwel/
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/