I just recently made a change from STATA to R and have some troubles implementing the R equivalent of the STATA commands xtlogit,fe or re
and predict
. May I ask for some assistance to adjust the following scenario:
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
Additionally, I would like to do these procedure for random effects and fixed effects. So I tried random effects first unsuccessfully:
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"))
But that doesnt seem to work. May I ask for how to adjust the glm
model regarding random effects and fixed effects in order to use the predict
function.