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

Ben Bolker bbolker at gmail.com
Fri Jun 3 21:31:49 CEST 2011


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




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