R中的预测概率

时间:2014-04-15 18:39:18

标签: r probability logistic-regression

我有一个带虚拟变量的logit模型,我想在renting = 0和renting = 1时绘制预测变量。创建cex2对象后,我收到一条错误消息:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev =          object$xlevels) : variable lengths differ (found for 'clt2')
In addition: Warning message:
'newdata' had 100 rows but variables found have 4139 rows 

任何想法都会受到赞赏。

model1<-glm(adaycare~fincbtax+I(fincbtax^2)+clt2+clt6+got6+bot6+renting,    family="binomial")
summary(model1)

exp(coef(model1))

#predicted values

newcex <-with(cex,data.frame(fincbtax=mean(fincbtax),clt2=mean(clt2),clt6=mean(clt6),got6=mean(got6),bot6=mean(bot6),renting=(1:0)))
newcex$rentingProb<-predict(model1,newdata=newcex,type="response")

cex2<-with(cex,data.frame(fincbtax=rep(seq(from=10000,to=500000,length.out=50),2),renting=(rep(0:1,each=50))))

cex3<-cbind(cex2,predict(model1,cex2,type="link",se=TRUE))

cex3 <- within(cex2, {
  PredictedProb <- plogis(fit)
  LL <- plogis(model1 - (1.96 * se.fit))
  UL <- plogis(fit + (1.96 * se.fit))
})

0 个答案:

没有答案