Getting MCMC residuals and their chains from RS model

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
andrewjdbell
Posts: 17
Joined: Mon Jun 03, 2013 3:19 pm

Getting MCMC residuals and their chains from RS model

Post by andrewjdbell »

Hi,

I am running a model with 8 level 2 variances (a diagonal matrix with 8 coefficients allowed to vary), on a sample of 20 level 2 units (countries), in MCMC with MLwiN. I want to output the residuals' chains (so that I can calculate things like coverage intervals around beta0+u0j).

I tried to do this through runmlwin - using the code

residuals(u, savechains("u.dta", replace))

but MLwiN crashed (the model ran fine, but it crashed once the run had finished but before it had sent the output to Stata). Any ideas why this would be? I thought it might be a memory issue but it crashes even when I only run 10 iterations... It works fine without the residuals option specified.

Thanks!
Andy

PS: my full code is:

runmlwin Y cons X1 X2 X3 X4 X5 X6 X7, ///
level2(Country: cons X1 X2 X3 X4 X5 X6 X7, diagonal) ///
level1(Year: cons) nopause

mat A = e(b)
mat A[1,15] = 0.001 //so the variance matrix is positive definte

runmlwin Y cons X1 X2 X3 X4 X5 X6 X7, ///
level2(Country: cons X1 X2 X3 X4 X5 X6 X7, ///
residuals(u, savechains("u.dta", replace)) diagonal) level1(Year: cons) ///
mcmc(chain(5000) burnin(500)) initsb(A)
ChrisCharlton
Posts: 1351
Joined: Mon Oct 19, 2009 10:34 am

Re: Getting MCMC residuals and their chains from RS model

Post by ChrisCharlton »

Currently MLwiN only allocates enough space for residual columns as the maximum number of variables allowed in the model, which in runmlwin we set based on the number of variables specified. As saving residuals needs a column for the residual and its standard error this means that if you have more than half the total number of variables in the model made random at a level MLwiN won't have enough space and you will encounter the crash that you saw. I will fix this in MLwiN version 2.29, however in the mean time you can work around it by increasing the maximum number of variables allowed with mlwinsettings() option, e.g.

Code: Select all

mlwinsettings(variables(20))
Post Reply