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

Ben Bolker bbolker at gmail.com
Thu Jun 2 20:33:05 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 ...


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3n12EACgkQc5UpGjwzenOYXwCgmvNdYn88ULVeFDA518vpss2x
4f4An0egTw+Z6KQ7/wpMRV2rYxbxl/Nf
=72ba
-----END PGP SIGNATURE-----




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