[R-sig-ME] making predictions with MCMCglmm

YA x|nx|813 @end|ng |rom 126@com
Fri May 29 11:25:16 CEST 2020


Dear list,


I am still working on the MCMCglmm predictions. I realized that I didnt provide a reproducible code in my last email, which makes people here lack of clues for helping me. I am providing a reproducible example this time using datasets from the nlme package, so if you have any experience on this package, please give me some advice on programming the predictions. As you can see below, same error occured on different models, I guess something is wrong with my code. Thank you very much.


> library(MCMCglmm)
> library(nlme)
> data(MathAchieve,package='nlme')
> data(MathAchSchool,package='nlme')
> dat=merge(MathAchSchool,MathAchieve,by='School')
> dat$mathach[dat$MathAch<5]=0
> dat$mathach[dat$MathAch>=5 & dat$MathAch<15]=1
> dat$mathach[dat$MathAch>=15]=2
> dat$mathach=as.factor(dat$mathach)
> str(dat)


# prediction on a continous outcome 'MathAch'

> m1=MCMCglmm(MathAch~Sex+SES,random=~School+SES,dat=dat,verbose=F)
> summary(m1)
> predict(m1,data.frame(Sex='Male',SES=c(0.3,-0.8)),type='response')
Error in FUN(X[[i]], ...) : object 'MathAch' not found


# prediction on a binary outcome 'Sex'
> m2=MCMCglmm(Sex~SES,random=~School+SES,data=dat,family='categorical',verbose=F) 
> summary(m2)
> predict(m2,data.frame(SES=0.5,School='1224'),marginal=NULL,type='response')
Error in FUN(X[[i]], ...) : object 'Sex' not found



# prediction on a three category unordered multinomial outcome 'mathach'

> m3=MCMCglmm(mathach~SES,random=~School+SES,data=dat,rcov=~us(trait):units,family='categorical',verbose=F) 
> summary(m3)
> predict(m3,data.frame(SES=0.5,School='1224'),marginal=NULL,type='response')
Error in FUN(X[[i]], ...) : object 'mathach' not found


Best regards,


YA
	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list