我最近刚刚从 STATA 更改为 R,并且在实现 STATA 命令的 R 等效项xtlogit,fe or re
和predict
. 我可以请求一些帮助来调整以下场景:
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"))
但这似乎不起作用。请问如何调整glm
随机效应和固定效应的模型以使用该predict
功能。