Specifying weight in R2MLwiN

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN 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 R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
vivian1234
Posts: 30
Joined: Tue Apr 12, 2016 10:54 am

Specifying weight in R2MLwiN

Post by vivian1234 » Thu Jan 12, 2017 3:33 pm

Hi,

I would like to know if it is possible to specify sampling weight in R2MLwiN when fitting multilevel model. I know that this can be done through using the software and runmlwin in STATA. However, as I'm a R user, I also want to know how to specify weights in R2MLwiN.

Thanks.

Vivian

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

Re: Specifying weight in R2MLwiN

Post by ChrisCharlton » Thu Jan 12, 2017 5:51 pm

Yes this should be possible, although currently the help text is not properly attached to the runMLwiN() function. The relevant text for the option is:

weighting - A list of two items, one of which is a list called weightvar the length of which corresponds to the number of levels in the model, in descending order from highest level first. The other is an option standardised which is TRUE or FALSE

This option is added to with the estoption list when you call R2MLwiN.

If you wanted to add standardised weights for the student level of the example data, where the raw weights were in a variable called stweights, the syntax should be something like the following:

Code: Select all

runMLwiN(normexam ~ 1 + standlrt + (1|school) + (1|student), estoptions=list(weighting=list(weightvar=c(NA, "stweights"), standardised=TRUE)), data=tutorial)

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying weight in R2MLwiN

Post by adeldaoud » Tue Apr 17, 2018 10:35 pm

Hi Chris,

Trying to add weights in a four-level mode and only for the first level. I assume this is a correction estimation option argument:

Code: Select all

estoptions = list(EstM = 0, optimat=T,  resi.store = TRUE, debugmode=F,
                  weighting = list(weightvar=c(NA,NA,NA, "wg"), standardised=T))

Code: Select all

f2 = as.formula(abspov ~ 1 + sex + caste + religion + citytown + Adults_child +  age  + Harriss + GDP20042005 + TII_2008 + (1|Rregion) + (1|Rcluster) + (1|Rhouseid) + (1|Rid))

mTII_Harriss_fl_tii_2008=runMLwiN(f2, D="Normal", data = indata, estoptions = estoptions)
However, I get the following error
/nogui option ignored
ECHO 0


Error in read.dta(IGLSfile) :
unable to open file: 'No such file or directory'
In addition: Warning message:
running command '"C:/Program Files/MLwiN v3.01//mlnscript.exe" /nogui /run "C:/Users/daoud/AppData/Local/Temp/Rtmps9mOFK/macrofile_135387b6a95a.txt"' had status 1033

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

Re: Specifying weight in R2MLwiN

Post by ChrisCharlton » Wed Apr 18, 2018 9:08 am

If no results are returned then it is likely that there was an estimation error. Could you try adding the debugmode=TRUE option and then checking within the MLwiN interface whether any errors are reported?

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying weight in R2MLwiN

Post by adeldaoud » Wed Apr 18, 2018 12:33 pm

Could you try adding the debugmode=TRUE option and then checking within the MLwiN interface whether any errors are reported?
When I enter debugmode I discover that Mlwin crashes. I tried varying the following arguments, but it still crashes:

optimat=,
resi.store = ,
x64= ,
weighting = list(weightvar=c(NA,NA,NA, "wg"), standardised= )

Ideas appreciated. (Four-level weighting worked in previous versions of Mlwin but now when I re-estimate some old models I discover that it does not work anymore)

vivian1234
Posts: 30
Joined: Tue Apr 12, 2016 10:54 am

Re: Specifying weight in R2MLwiN

Post by vivian1234 » Wed Apr 18, 2018 12:35 pm

Hi, I have a similar problem before. However, the problem was solved after I upgraded the MLwiN to version 3.02 and installed R2MLwiN using

Code: Select all

library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
http://www.bristol.ac.uk/cmm/software/r2mlwin/


Vivian

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

Re: Specifying weight in R2MLwiN

Post by ChrisCharlton » Wed Apr 18, 2018 12:48 pm

There was a bug with weighting introduced in MLwiN 3.01 (see viewtopic.php?f=3&t=2573), which this would correspond to.

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying weight in R2MLwiN

Post by adeldaoud » Wed Apr 18, 2018 9:57 pm

Thanks to both of you. I missed this solution while browsing through the topics. I confirm this works.

On a related note. I wonder how rp- and fpsandwish works for weighting? The manual states:
weighting: a deprecated option for specifying weights in IGLS estimation: see fpsandwich
and rpsandwich for new method of doing so. weighting is a list of objects including levels,
weights, mode, FSDE and RSDE; see write.IGLS for details
I know that rp- and fpsanwish swith on sandwiched SE, but how does that relate to weighting (e.g. using case specific sample weights)?
fpsandwich: specifies standard error type for fixed parameters. If fpsandwich = TRUE,
robust or ‘sandwich’ standard errors based on raw residuals are used, if fpsandwich = FALSE
(default) then standard, uncorrected, IGLS or RIGLS computation used.

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

Re: Specifying weight in R2MLwiN

Post by ChrisCharlton » Mon Apr 23, 2018 9:38 am

If you specify weights in your model then the default for the fpsandwich and rpsandwich options change from FALSE to TRUE.

Post Reply