Predict random effects of interest

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
sujust18
Posts: 6
Joined: Wed Dec 05, 2012 4:54 pm

Predict random effects of interest

Post by sujust18 »

Hello everybody,

I'm running a MCMC logit model with crossed random effects.
Is there a way to give out the particular random effect and to predict the effects as if I were using a fixed-effects approach?

I have groups of different people using random effects but would also like to get more insights into their particular behavior.

Thanks in advance!

Susann
GeorgeLeckie
Site Admin
Posts: 432
Joined: Fri Apr 01, 2011 2:14 pm

Re: Predict random effects of interest

Post by GeorgeLeckie »

Hi Susan,

Yes you can retrieve the estimates of the random effects after fitting a cross-classified model using MCMC.

The following syntax provides an example...

Code: Select all

* Open the example data set
use http://www.bristol.ac.uk/cmm/media/runmlwin/xc, clear

* Summarize the variables in the data set
summarize

* Specify starting values for the model parameters
matrix b = (0,.33,.33,.33)

* Fit the cross-classified model
runmlwin attain cons, ///
	level3(sid: cons, residuals(v)) ///
	level2(pid: cons, residuals(u)) ///
	level1(pupil: cons) ///
	mcmc(cc) initsb(b) nopause

* Summarize the variables in the data set
summarize
and here is the corresponding output...

Code: Select all

. * Open the example data set
. use http://www.bristol.ac.uk/cmm/media/runmlwin/xc, clear

. 
. * Summarize the variables in the data set
. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         vrq |      3435    97.80437    13.29291         70        140
      attain |      3435    5.678603    3.058504          1         10
         pid |      3435     70.7377    45.02572          1        148
         sex |      3435    .4937409    .5000336          0          1
          sc |      3435    6.844833    10.88761          0         31
-------------+--------------------------------------------------------
         sid |      3435    10.21951     5.55694          1         19
         fed |      3435    .2754003    .4467808          0          1
      choice |      3435    1.195342    .6502375          1          4
         med |      3435     .342067     .474471          0          1
        cons |      3435           1           0          1          1
-------------+--------------------------------------------------------
       pupil |      3435     18.1278    13.54164          1         72

. 
. * Specify starting values for the model parameters
. matrix b = (0,.33,.33,.33)

. 
. * Fit the cross-classified model
. runmlwin attain cons, ///
>         level3(sid: cons, residuals(v)) ///
>         level2(pid: cons, residuals(u)) ///
>         level1(pupil: cons) ///
>         mcmc(cc) initsb(b) nopause
 
MLwiN 2.27 multilevel model                     Number of obs      =      3435
Normal response model
Estimation algorithm: MCMC

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
            sid |       19         92      180.8        290
            pid |      148          1       23.2         72
-----------------------------------------------------------

Burnin                     =        500
Chain                      =       5000
Thinning                   =          1
Run time (seconds)         =       8.81
Deviance (dbar)            =   16940.56
Deviance (thetabar)        =   16833.40
Effective no. of pars (pd) =     107.16
Bayesian DIC               =   17047.73
------------------------------------------------------------------------------
      attain |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
-------------+----------------------------------------------------------------
        cons |    5.50404   .1895742      278   0.000     5.107834    5.866227
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |     Mean   Std. Dev.   ESS     [95% Cred. Int]
-----------------------------+------------------------------------------------
Level 3: sid                 |
                   var(cons) |  .4140328   .209626   1111   .1419404  .9289979
-----------------------------+------------------------------------------------
Level 2: pid                 |
                   var(cons) |  1.152583  .2147315   1282   .7958307  1.625606
-----------------------------+------------------------------------------------
Level 1: pupil               |
                   var(cons) |  8.119921  .2017282   4581   7.733236  8.526891
------------------------------------------------------------------------------

. 
. * Summarize the variables in the data set
. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         vrq |      3435    97.80437    13.29291         70        140
      attain |      3435    5.678603    3.058504          1         10
         pid |      3435     70.7377    45.02572          1        148
         sex |      3435    .4937409    .5000336          0          1
          sc |      3435    6.844833    10.88761          0         31
-------------+--------------------------------------------------------
         sid |      3435    10.21951     5.55694          1         19
         fed |      3435    .2754003    .4467808          0          1
      choice |      3435    1.195342    .6502375          1          4
         med |      3435     .342067     .474471          0          1
        cons |      3435           1           0          1          1
-------------+--------------------------------------------------------
       pupil |      3435     18.1278    13.54164          1         72
          v0 |      3435     .101494    .4445142  -1.390685   .8053839
        v0se |      3435    .3470065    .0305675   .2995253   .4182785
          u0 |      3435    .0721174    .8719635   -2.12353   2.038133
        u0se |      3435    .5367325    .0936752   .4163686   1.014281

. 
end of do-file
The two sets of predicted random effects are stored in v0 and u0, while the standard errors of these estimates are stored in v0se and u0se

Best wishes

George
sujust18
Posts: 6
Joined: Wed Dec 05, 2012 4:54 pm

Re: Predict random effects of interest

Post by sujust18 »

Hi George,

Thank you so much for this fast and very helpful response!
It works perfectally!

I'd like to mention a little problem that I could solve on my own because others may find this helpful.

One of my clusters contains 15 agents (1-15). Initially, I got missing values for the predicted random effect for agent 1 (all the other agents and clusters worked fine).
I changed the numbering, agent 1 becoming number 16, and got the same problem with agent 2 then. So clearly, I could not get a predicted random effect for the agent with the lowest variable number.

I found that the variable agent was missing a single observation in the dataset . After deleting this observation everything works fine now and I get all the random effects. :D

Thanks again for your help!

Best wishes,

Susann
GeorgeLeckie
Site Admin
Posts: 432
Joined: Fri Apr 01, 2011 2:14 pm

Re: Predict random effects of interest

Post by GeorgeLeckie »

Hi Susann,

I am glad everything is now working

Might you be able to email me a do-file and data set which replicates the problem you describe so that we can set about implementing a fix? Please make this the simplest do-file and data set which replicates the problem.

Best wishes

George
GeorgeLeckie
Site Admin
Posts: 432
Joined: Fri Apr 01, 2011 2:14 pm

Re: Predict random effects of interest

Post by GeorgeLeckie »

Dear Susann,

Thank you for sending the files through.

Yes we have found the source of the problem. The explanation is complicated! But it looks like we have now fixed it for the next version.

Work around solution is to simply listwise delete your data before issuing the runmlwin command

Best wishes

George
Post Reply