How can I change the variance in the Runmlwin Command?

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/
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

How can I change the variance in the Runmlwin Command?

Post by likestatistic »

Hello,

I am using Runmlwin and mi estimate.
My sample vary by imputation number and I am getting a variance=0 for some of them and it prevent Runmlwin to continue (with esampvaryok).
Without the nopause option, I have tried to remplace variance= 0.0001 in MLwiN when it is estimate to 0 using:
pick 1 c1096 b1
calc b1=b1+(b1==0)*0.0001
edit 1 c1096 b1

and it work

Is there a way to include these changes directly in the Runmlwin command?

Many thanks for your help

L
ChrisCharlton
Posts: 1285
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I change the variance in the Runmlwin Command?

Post by ChrisCharlton »

The initsb option in -runmlwin- is the equivalent to editing the C1098 and C1096 columns in MLwiN. You can find an example of how to use this option in the following example: http://www.bristol.ac.uk/cmm/media/runm ... r_Seeds.do. Unfortunately this will always set the value to what you specify, rather than conditionally change it as in your example. If you wanted this additional functionality you would need to edit your changes into the runmlwin.ado file. To do this search for the following code, which applies the initial values by setting C1096:

Code: Select all

	* Random part initial values
	// Need to check that the correct number of initial values have been specified
	// what if no random part e.g. single level logit
	file write `macro1' "NOTE   Specify random part initial values" _n
	local names : colfullnames `matRP_b'
	local P = colsof(`matRP_b')
	local i = 1
	foreach p of local names {
		if `i'<=`P' {
			file write `macro1' "NOTE   `p'" _n
			mat `matINIT' = `matb'[1,"`p'"]
			file write `macro1' "EDIT `i' c1096  `=`matINIT'[1,1]'" _n
			local ++i
		}
	}
and make the changes as appropriate.
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

Re: How can I change the variance in the Runmlwin Command?

Post by likestatistic »

Many thanks ChrisCharlton for your response.
I have changed the initial value but the variance couldn't change (still going to 0).
I will try to change the runmlwin.do file directly, but I am not sure that I Know how to change the section you showed in order to make the following changes:
pick 1 c1096 b1
calc b1=b1+(b1==0)*0.0001
edit 1 c1096 b1

Can you help me?

Many thanks

L
ChrisCharlton
Posts: 1285
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I change the variance in the Runmlwin Command?

Post by ChrisCharlton »

To replicate what your code was doing previously you would want to change the code to something like:

Code: Select all

   * Random part initial values
   // Need to check that the correct number of initial values have been specified
   // what if no random part e.g. single level logit
   file write `macro1' "NOTE   Specify random part initial values" _n
   local names : colfullnames `matRP_b'
   local P = colsof(`matRP_b')
   local i = 1
   foreach p of local names {
      if `i'<=`P' {
         file write `macro1' "NOTE   `p'" _n
         mat `matINIT' = `matb'[1,"`p'"]
         file write `macro1' "EDIT `i' c1096  `=`matINIT'[1,1]'" _n
         file write `macro1' "PICK `i' c1096  b1" _n
         file write `macro1' "CALC b1=b1+(b1==0)*0.0001" _n
         file write `macro1' "EDIT `i' c1096  b1" _n
         local ++i
      }
   }
It's probably also worth checking that the macro is being generated correctly by adding the viewfullmacro option to your -runmlwin- command and checking the displayed output.
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

Re: How can I change the variance in the Runmlwin Command?

Post by likestatistic »

Hi ChrisCharlton,

Many thanks for your help.
Unfortunately, I couldn’t get it to work. The programme aborts because the variance is still going to 0. (I assume it is considering 0.0001 as a starting value so, the problem is not my starting value)

I noticed that when I change the variance manually from 0 to 0.0001 in MLwiN and press the button more, I am getting the same error as if the variance was 0 (the programme aborts).

After resuming the macro once, when I change the variance 0 to 0.0001 and resume the macro without rerunning the model (without more), it works. No error, no crash.

Is it because in the do file, after changing the variance from 0 to 0.0001, the model is rerunned before the resume?
I have attached an Excel file of and a word document summarizing the results. You could see that for imputation 8, the level3 variance is 0 and the programme abort if the value is not replaced by 0.0001 (and abort if you rerun the model after this change).

*Programme 1
sort area lev2 id
mi update
xi: mi est, cmdok noisily esampvaryok : runmlwin reponse cons i.per ye i.mo i.gend ges ges2 bm bmi2 ta ta2 i.par i.mar i.prim i.sim i.boosm i.smo if subgroup==1 , level3(area: cons) level2(lev2: cons) level1(id: cons) forcesort maxiterations(60) nopause mlwinpath(C:\Program Files (x86)\MLwiN v2.32\i386\MLwiN.exe)

Error message on imputation=8 (idem after changing the rumlwin do file)


*Programme 2
*The same programme but changing manualy level3 variance to 0.0001
sort area lev2 id
mi update
xi: mi est, cmdok noisily esampvaryok : runmlwin reponse cons i.per ye i.mo i.gend ges ges2 bm bmi2 ta ta2 i.par i.mar i.prim i.sim i.boosm i.smo if subgroup==1 , level3(area: cons) level2(lev2: cons) level1(id: cons) forcesort maxiterations(60) mlwinpath(C:\Program Files (x86)\MLwiN v2.32\i386\MLwiN.exe)

it works and I am getting the final result after on all impuations


I have attached the Results in a Word document. but my Excel table is too large and I couldn't download it here.

L
Attachments
Programmes and results.doc
(44.5 KiB) Downloaded 312 times
ChrisCharlton
Posts: 1285
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I change the variance in the Runmlwin Command?

Post by ChrisCharlton »

Sorry - yes I thought you were having problems with starting values rather than the output results. To make the change to the results you would want to find the following code:

Code: Select all

	local startrow = colsof(`matFP_b')
	* Put MLwiN values back into RP_b
	forvalues c = 1/`=colsof(`matRP_b')' {
		mat `matb'[1,`=`startrow'+`c''] = _RP_b[`c']
	}
and change it to:

Code: Select all

	local startrow = colsof(`matFP_b')
	* Put MLwiN values back into RP_b
	forvalues c = 1/`=colsof(`matRP_b')' {
		mat `matb'[1,`=`startrow'+`c''] = _RP_b[`c']
		if _RP_b[`c'] == 0 {
			mat `matb'[1, `=`startrow'+`c''] = 0.0001
		}
	}
An output value of zero for this variance may indicate a problem with the model or data, so it's probably worth investigating that too.
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

Re: How can I change the variance in the Runmlwin Command?

Post by likestatistic »

I am running the model on a sudgoup of an imputed variable. So I have different sample size by imputation number.
In some of them like imputation4 I have few observation at level3.
So all the programme abort at imputation 4 because level3 variance is 0 and the Rubin rule couldn't continue.

(running runmlwin on m=4)

MLwiN 2.32 multilevel model Number of obs = 8420
Normal response model
Estimation algorithm: IGLS

-----------------------------------------------------------
| No. of Observations per Group
Level Variable | Groups Minimum Average Maximum
----------------+------------------------------------------
area | 4264 1 2.0 29
lev2 | 7889 1 1.1 4
-----------------------------------------------------------


I am still getting variance 0 after making the change you suggested


------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 3: area |
var(cons) | 0 0 0 0
-----------------------------+------------------------------------------------
Level 2: lev2 |
var(cons) | 120903.6 8771.266 103712.3 138095
-----------------------------+------------------------------------------------
Level 1: id |
var(cons) | 142532.3 8251.953 126358.8 158705.8
------------------------------------------------------------------------------

L
ChrisCharlton
Posts: 1285
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I change the variance in the Runmlwin Command?

Post by ChrisCharlton »

Odd, I just tested the change and it worked for me. Two possibilities are:

1) You haven't reloaded the runmlwin command after making the change by restarting Stata or issuing the discard command.

2) The value returned from MLwiN isn't exactly zero, in which case you could turn the condition into:

Code: Select all

if _RP_b[`c'] < 0.0001 {
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

Re: How can I change the variance in the Runmlwin Command?

Post by likestatistic »

Brilliant :idea: ! It works. :D

Many many thanks

L
likestatistic
Posts: 39
Joined: Fri Sep 12, 2014 4:11 pm

Re: How can I change the variance in the Runmlwin Command?

Post by likestatistic »

Hi ChrisCharlton,

Changing column c1096 value to 0.0001 if 0 resolve my problem when I am running a model on imputed data (the Rubin rules is no longer crashing).
But it has created another issue when I am using the model on complete cases. I am getting the following message:

estimates post: matrix has missing values
Warning - runmlwin has experienced difficulties importing the standard errors, all standard errors have been set to zero
estimates post: matrix has missing values

Is there a way to add a condition in the ado file so that the change is made only if the model is running on imputation file?

Many thanks

L
Post Reply