[R-sig-ME] How to write random effect for mixed model in MCMCglmm

Jarrod Hadfield j.hadfield at ed.ac.uk
Sat Jun 4 21:00:42 CEST 2011


Hi,

These are the observation level variances and covariances for each  
category of the response, where Level.2:Level.2.units is the  
observation-level variance of the Level 2 contrast, and  
Level.3:Level.2.units the observation-level covariance between the  
Level 2 and Level 3 contrasts. If the data are multinomial with >1  
trial then these can be estimated, but if there is only one trial  
(i.e. catgorical data as here) they cannot be. In this case it makes  
sense to fix the observation-level (co)variance matrix at some value.  
I use:

IJ <- (1/n) * (diag(n-1) + matrix(1, n-1, n-1))
prior = list(R = list(V = IJ, fix = 1))

where n is the number of categories, but the choice is rather  
arbitrary. The posterior for the fixed effects and the identifiable  
(co)variances associated with the clustering can be rescaled by your  
choice of observational-level variances - see P97 of the CourseNotes.

Cheers,

Jarrod

Quoting Ping Yi <ping.yi at gmail.com> on Fri, 3 Jun 2011 16:14:01 -0700:

> Ben,
>
> Thanks a lot, I finally got the results although It took a long time for R
> to run.
>
> This is my first time using MCMCglmm package, so I have a hard time to
> interpret the results.  Do you know where I can find the information of how
> to interpret of the results?
>
> Here are some of the results:
>
> R-structure:  ~us(trait):units
>
>                          post.mean  l-95% CI u-95% CI eff.samp
>
> Level.2:Level.2.units    4.2650   3.45197   4.9409    2.490
>
> Level.3:Level.2.units   -1.0528  -1.56227  -0.5718    3.917
>
> Level.4:Level.2.units    0.3431   0.14440   0.5322    5.793
> What does level1.2:level1.2.units mean, and what does eff.samp stand for?
>
> Thanks
>
> On Fri, Jun 3, 2011 at 12:31 PM, Ben Bolker <bbolker at gmail.com> wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 06/03/2011 01:10 PM, Ping Yi wrote:
>> > I re-ran R again (without missing values), and this time, R kept running.
>> I
>> > have 23658 obs with 63 variables. Is my data set out of memory, or there
>> are
>> > something wrong in MCMCglmm()?
>>
>>   For mixed models, this is in the realm of "large data".  In general
>> MCMC approaches are very flexible and have lots of nice properties, but
>> speed is not one of them (although MCMCglmm is far faster than, say,
>> coding an equivalent model in WinBUGS).
>>
>>  I would suggest that you try some experiments on some subsets of your
>> data (e.g., 1000 observations and 10 variables; 2000 observations and 10
>> variables; 1000 observations and 20 variables) to get a sense of how the
>> running time scales with data size, and then see if you need to find
>> another tool.
>>
>> >
>> > On Fri, Jun 3, 2011 at 9:47 AM, Ping Yi <ping.yi at gmail.com> wrote:
>> >
>> >> Hi Ben,
>> >>
>> >> I have deleted the missing values, but i still got the same error. What
>> >> else I can do for it?
>> >>
>> >> Thanks for the help.
>> >>
>> >>
>> >>
>> >>
>> >> On Thu, Jun 2, 2011 at 11:33 AM, Ben Bolker <bbolker at gmail.com> wrote:
>> >>
>> > On 06/02/2011 02:19 PM, Ping Yi wrote:
>> >>>>> Hi,
>> >>>>>
>> >>>>> I have posted this on R-help, but I have not got more information so
>> > far.
>> >>>>> Bbolker<
>> >
>> http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=23641
>> >>>>> suggests
>> >>>>> that I should re-post it here, and see if I can get further help.
>> >>>>>
>> >>>>> The data set that I have is a cluster data, and I want to run a HLM
>> > mixed
>> >>>>> model with multi-level response. Here is my data set:
>> >>>>> response:
>> >>>>>    - Level (num:  1, 2, 3, 4, 5 - 5 levels)
>> >>>>> Covariates:
>> >>>>>    - Type (Factor: A, B, C - 3 levels)
>> >>>>>    - yr (num: 2006, 2007, ...)
>> >>>>>    - Male (num: 0=not Male, 1=Male - 2 levels)
>> >>>>>    - Ethnicity (Factor: A, B, H, ..., - 7 levels)
>> >>>>>    - ELL (num: 0, 1, - 2 levels)
>> >>>>>    - Disability (num: 0, 1, - 2levels)
>> >>>>>    - avgTransfers (num with missing values)
>> >>>>>    - sdTransfers (num with missing values)
>> >>>>>    - agec (num with missing values)
>> >>>>>    - PctELL (num)
>> >>>>>    - PctDisability (num)
>> >>>>>    - PctMale (num)
>> >>>>> Random Effects:
>> >>>>>    - Schoolid, Teacherid, Studentid
>> >>>>>
>> >>>>> library(MCMCglmm)
>> >>>>> y <- MCMCglmm(factor(Level) ~
>> Type+factor(yr>=2006)+Male+Ethnicity+ELL+
>> >>>>>
>> >>>>>
>> >
>> avgTransfers+sdTransfers+agec+Disability+ELL*pctELL+Disability*pctDisability+
>> >>>>>
>> >>>>>           pctMale+factor(yr>=2008)*factor(Grade),
>> >>>>> random=~Schoolid+Teacherid+Studentid,
>> >>>>>           family="categorical", data=data[data$Grade>=4,])
>> >>>>>
>> >>>>> *Error in MCMCglmm(FCATprofLevel ~ transferTypeCat + factor(yr >=
>> 2008)
>> > +  :
>> >>>>>
>> >>>>> please use idh(trait):units, us(trait):units or trait:units for error
>> >>>>> structures involving catgeorical data with more than 2 categories*
>> >>>>>
>> >>>>> I also read chapter 5 of the course notes vignette, and I tried codes
>> > below:
>> >>>>>
>> >>>>> library(MCMCglmm)
>> >>>>> y <- MCMCglmm(factor(Level) ~
>> Type+factor(yr>=2006)+Male+Ethnicity+ELL+
>> >>>>>
>> >>>>>
>> >
>> avgTransfers+sdTransfers+agec+Disability+ELL*pctELL+Disability*pctDisability+
>> >>>>>
>> >>>>>           pctMale+factor(yr>=2008)*factor(Grade),
>> rcov=~us(trait):units,
>> >>>>> random=~Schoolid+Teacherid+Studentid,
>> >>>>>           family="categorical", data=data[data$Grade>=4,],
>> > verbose=FALSE)
>> >>>>>
>> >>>>> *Error in buildZ(rmodel.terms[r], data = data) : missing values in
>> > random
>> >>>>> predictors*
>> >>>>>
>> >>>>> Does anyone know how to fix it, or if there are any other methods
>> that
>> > can
>> >>>>> run this model?
>> >
>> >   Try removing missing values (NAs) and see if that helps?  (It's
>> > conceivable that the NAs aren't in your data set but have been produced
>> > in the process of generating the data structures for multilevel data,
>> > but it would definitely be worth trying data =
>> > na.omit(subset(data,Grade>=4)) as a first pass ...
>> >
>> >
>> >>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Best regards,
>> >> Ping
>> >>
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.10 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAk3pNqUACgkQc5UpGjwzenN/owCfcj5NXsm/TWjfYLGSrU+Z3/zw
>> XxMAoJ60obNziIBlvf36djI6E4R5zqgc
>> =JBtm
>> -----END PGP SIGNATURE-----
>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>
>
>
> --
> Best regards,
> Ping
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>



-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




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