I was messing with zelig (namely logistic
regression) on a data set with
categorical covariates:
hisp = 0 or 1
coll = 0 or 1
inc = 1, 2 or 3
I get the following error with the setx() step:
z1 <- zelig(grad ~ factor(hisp) + factor(coll)
+ factor(inc),
model="logit",
data=hsgrad)
x1 <- setx(z1, coll=0)
Error in "contrasts<-"(`*tmp*`, value =
"contr.treatment") :
contrasts can be applied only to factors with 2 or more levels
I tried
x1 <- setx(z1, factor(coll)=0)
Error in
"contrasts<-"(`*tmp*`, value = "contr.treatment") :
contrasts can be applied only to factors with 2 or more levels
and got the same error. However, when I make the variables into factors
within the dataframe, things work:
hsgrad$f1 = factor(hsgrad$coll)
hsgrad$f2 = factor(hsgrad$hisp)
hsgrad$f3 = factor(hsgrad$inc)
z1 <- zelig(grad ~ f1+f2+f3, model="logit", data=hsgrad)
x1 <- setx(z1, f1=1)
s1 <- sim(z1,x1)
Was wondering whether this step is always necessary when dealing with
categorical covariates or is there an easier way to setx() and do things
like
the above?
You might try something like:
x1 <- setx(z1, f1='1')
I'm not 100% positive it will work, though. Parsing R formulas is
something of a black art, particularly when trying to do some of the
fancy stuff Zelig does behind the scenes.
You might also try using as.factor() instead of factor()... it
shouldn't make a difference, but there may be some subtleties in
formula parsing that affect things in this case.
Chris
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: