Hi
I am hoping to use Zelig to estimate a GAM model. I have run into some
problems in generating predicted values. Specifically, the predictions I get
using Zelig don't make substantive sense and are different from predictions
I get using the mgcv package.
I have created an example of the problem using the turnout data set:
data(turnout)
#######################################
## Using Zelig
zel.out<-zelig(vote~s(age) +educate +income, sp=c(.001),
model="probit.gam", data=turnout)
pred.zel.out<-cbind(rep(NA,63), rep(NA,63))
for(i in 18:80){
x.out<-setx(zel.out, age=i)
s.out<-sim(zel.out, x=x.out)
pred.zel.out[i-17,2]<-summary(s.out)$qi.stats$pr[1]
pred.zel.out[i-17,1]<-i
}
pred.zel.out
#Note: I used a loop since the usual command (see next line) does not
work:
x.out<-setx(zel.out, age=18:80)
#######################################
#######################################
## Using MGCV:
wood<-gam(vote~s(age) +educate +income, sp=c(.001),
family=binomial(link=probit), data=turnout)
pred.wood.in<-as.data.frame(matrix(NA, 63, 3))
names(pred.wood.in)<-c("educate", "income", "age")
pred.wood.in$age<-18:80
pred.wood.in$educate<-x.out$educate
pred.wood.in$income<-x.out$income
pred.wood.out<-predict.gam(wood, pred.wood.in, se.fit=TRUE,
type="response") #######################################
## Compare coeff estimates from MGCV and Zelig: (Coefficients are the same)
wood$coef
zel.out$coef
wood$coef==zel.out$coef
## Compare predicted values using MGCV and Zelig:
par(mfrow=c(1,2))
plot(pred.zel.out)
lines(pred.zel.out)
plot(pred.wood.in$age, pred.wood.out$fit)
lines(pred.wood.in$age, pred.wood.out$fit)
#######################################
-
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/