【发布时间】:2015-09-26 17:50:23
【问题描述】:
我最近刚刚从 STATA 更改为 R,在实现与 STATA 命令xtlogit,fe or re和predict 等效的 R 时遇到了一些麻烦。我可以请求一些帮助来调整以下场景:
data <- read.table("http://people.stern.nyu.edu/wgreene/Econometrics/healthcare.csv",header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
require(caret) # for confusionMatrix
#### subset into test & train according to the panel nature (split individuals rather then observations)
nID <- length(unique(data$id))
p = 0.50# partition
inTrain <- sample(unique(data$id), round(nID * p), replace=FALSE)
training <- data[data$id %in% inTrain, ]
testing <- data[!data$id %in% inTrain, ]
pooled <- glm(WORKING~WHITEC+FEMALE+BLUEC+HHNINC+AGE+AGESQ+EDUC+DOCVIS,data=training, family=binomial(link="logit"))
prediction.working= round(predict(pooled,newdata=testing,type="response"))
confusionMatrix(prediction.working,testing$WORKING) # Accuracy between both
此外,我想为随机效果和固定效果执行这些程序。所以我先尝试了随机效果,没有成功:
library(glmmML)
RE <- glmmML(WORKING~WHITEC+FEMALE+BLUEC+HHNINC+AGE+AGESQ+EDUC+DOCVIS, family=binomial(link="logit"), data=training, cluster=id, method="ghq", n.points=12)
prediction.working= round(predict(RE,newdata=testing,type="response"))
但这似乎不起作用。请问如何调整glmmodel的随机效应和固定效应,以便使用predictfunction。
【问题讨论】:
-
我认为您正在寻找条件 logit 模型。试试cran.r-project.org/web/packages/mclogit/mclogit.pdf
标签: r glm predict generic-function