Dear All,
Zelig 4 no longer seems to handle predict() and fitted() as it used to, and as other R
packages do.
In short, given a zelig output object (say "zelig.reg"), it seems that it is
necessary to invoke predict and/fitted on zelig.reg$result or zelig.reg[[1]] , and not on
zelig.reg. And the behavior of functions is not consistent across different models, at
least not across "ls" and "logit". A self contained example follows
below.
1 - Can the default method for these functions be changed to behave as before (i.e. to
accept predict(zelig.reg) and fitted(zelig.reg)?
2 - Can the behavior of predict() and fitted() be made consistent across models?
#I'm running:
#R version 3.0.0 (2013-04-03)
#Platform: x86_64-apple-darwin10.8.0 (64-bit)
#Running Zelig_4.1-3
data(npk, package="MASS") #load data
### Extracting fitted and predicted values from linear and logit regressions *not* using
Zelig, all this works well:
lm.reg <- lm(yield~N+P+K, data=npk)
predict(lm.reg)
fitted(lm.reg)
logit.reg <- glm(N~yield+P, data=npk, family=binomial(link="logit"))
predict(logit.reg)
fitted(logit.reg)
### Extracting fitted and predcited values from linear and logit regressions using Zelig
lm.zelig <- zelig(yield~N+P+K, data=npk,model="ls",cite=F)
predict(lm.zelig) # does not work
predict(lm.zelig[[1]]) #this "sort"of works, but spits back only 10
observations
predict(lm.zelig$result) #this does not work in "ls", but does work below in
"logit"
predict(lm.zelig$result,newdata=lm.zelig$data) #this seems to work, but is not
convenient...
fitted(lm.zelig) # does not work, but in the linear case does not matter
fitted(lm.zelig$result,newdata=lm.zelig$data) #this seems to work, but is not
convenient...
logit.zelig <- zelig(N~yield+P, data=npk, model="logit",cite=F)
predict(logit.zelig) # does not work
predict(logit.zelig$result) #this works, but is inconvenient
predict(logit.zelig$result,newdata=logit.zelig$data)
fitted(logit.zelig$result) #this seems to work in "logit", but does not work in
"lm"
Thank you,
cz
Cesar Zucco Jr.
Assistant Professor
Political Science Department
Rutgers, The State University of New Jersey
http://fas-polisci.rutgers.edu/zucco/