I want to calculate predicted values and standard errors, but I can't simply use predict(), as I’m using 15 multiply imputed datasets (Amelia package generated). I run regression models on each dataset. Afterwards, results are combined into a single set of model coefficients and standard errors using the Amelia function mi.meld(), which uses Rubin’s rule.
Sample data and code:
dd<-list()
for (i in 1:15){
dd[[i]] <- data.frame(
Age=runif(50,20,90),
Cat=factor(sample(0:4, 50, replace=T)),
Outcome = sample(0:1, 50, replace=T)
)}
b.out<-NULL
se.out<-NULL
for(i in 1:15) {
ols.out<-glm(Outcome~Age+factor(Cat), data=dd[[i]],family="binomial")
b.out <- rbind(b.out, ols.out$coef)
se.out <- rbind(se.out, coef(summary(ols.out))[,2])}
mod0 <- mi.meld(q = b.out, se = se.out)
> mod0
$q.mi
(Intercept) Age factor(Cat)1 factor(Cat)2 factor(Cat)3 factor(Cat)4
[1,] 0.0466825 -0.00577106 0.5291908 -0.09760264 0.4058684 0.3125109
$se.mi
(Intercept) Age factor(Cat)1 factor(Cat)2 factor(Cat)3
factor(Cat)4
[1,] 1.863276 0.02596468 1.604759 1.398322 1.414589
1.332743
Now comes the problematic part. I want to calculate predicted values (in this case, predicted probabilities) and standard errors for the following set of predictor values:
data.predict <- data.frame(Cat=as.factor(c(0:4)), Age=53.6)
print(data.predict)
Cat Age
1 0 53.6
2 1 53.6
3 2 53.6
4 3 53.6
5 4 53.6
If I had fitted a model on 1 dataset, I would simply do this:
prediction<- predict(mod1, data.predict, type="response",se.fit=T)
However, I don't have a model object, I just have coefficients stored.. Now I have looked into two ways of solving this, the first being manually calculating the predictions in this way: predict() with arbitrary coefficients in r However I don't know how to get to the standard errors.. The other idea I had was to create a fake model object, like this function creates: https://gist.github.com/MrFlick/ae299d8f3760f02de6bf and to use it in predict(), but as the standard errors of the model aren't used, there is also no way of calculating the standard errors of the prediction..
Does anyone have a suggestion on how to solve this? I have tried to explain my problem clearly and with sample code, but if my question somehow isn't clear, please let me know so I can provide additional information. Thank you for your help!