[R-sig-ME] making predictions with MCMCglmm

sree datta @reedt@8 @end|ng |rom gm@||@com
Fri May 29 18:21:32 CEST 2020


Dear YA

I noticed  the following in your code:

> > dat$mathach[dat$MathAch>=15]=2
> > dat$mathach=as.factor(dat$mathach

the dat$MathAch variable in line 1 will be processed as a variable
different from dat$mathach on line 2 - Is this what you planned for? Since
R is case-sensitive, this can create the problems you are seeing -
The error "*object mathach not found*" is likely a direct result of that.

Sree

On Fri, May 29, 2020 at 7:39 AM Tom Houslay <houslay using gmail.com> wrote:

> Hi YA,
>
> In your new data frame you just need to add a column for the response
> variable as well (set it to 0 or similar). You may have additional issues
> but that should get you over that first hurdle.
>
> Speaking of which, I've found when predicting from MCMCglmm that it doesn't
> like it when you only have a single value for any of your fixed effects --
> so you may want to expand your prediction data frames, for example for m1
> you could predict on those 2 SES values for both sexes (even if you are
> only interested in males, you can simply subset the predictions
> afterwards).
>
> Cheers
>
> Tom
>
>
> On Fri, 29 May 2020 at 11:01, <r-sig-mixed-models-request using r-project.org>
> wrote:
> >
> >
> >
> > Message: 1
> > Date: Fri, 29 May 2020 17:25:16 +0800
> > From: "YA" <xinxi813 using 126.com>
> > To: "r-sig-mixed-models" <r-sig-mixed-models using r-project.org>
> > Subject: [R-sig-ME] making predictions with MCMCglmm
> > Message-ID: <tencent_5701AD3CAB070C10E27910A2F3481E517A06 using qq.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> > 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]]
> >
> >
> >
> > ------------------------------
> >
> > Subject: Digest Footer
> >
> > _______________________________________________
> > R-sig-mixed-models mailing list
> > R-sig-mixed-models using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >
> >
> > ------------------------------
> >
> > End of R-sig-mixed-models Digest, Vol 161, Issue 44
> > ***************************************************
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]



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