Page 1 of 1

Specifying weight in R2MLwiN

Posted: Thu Jan 12, 2017 3:33 pm
by vivian1234
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

Re: Specifying weight in R2MLwiN

Posted: Thu Jan 12, 2017 5:51 pm
by ChrisCharlton
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)

Re: Specifying weight in R2MLwiN

Posted: Tue Apr 17, 2018 10:35 pm
by adeldaoud
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

Re: Specifying weight in R2MLwiN

Posted: Wed Apr 18, 2018 9:08 am
by ChrisCharlton
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?

Re: Specifying weight in R2MLwiN

Posted: Wed Apr 18, 2018 12:33 pm
by adeldaoud
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)

Re: Specifying weight in R2MLwiN

Posted: Wed Apr 18, 2018 12:35 pm
by vivian1234
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

Re: Specifying weight in R2MLwiN

Posted: Wed Apr 18, 2018 12:48 pm
by ChrisCharlton
There was a bug with weighting introduced in MLwiN 3.01 (see viewtopic.php?f=3&t=2573), which this would correspond to.

Re: Specifying weight in R2MLwiN

Posted: Wed Apr 18, 2018 9:57 pm
by adeldaoud
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.

Re: Specifying weight in R2MLwiN

Posted: Mon Apr 23, 2018 9:38 am
by ChrisCharlton
If you specify weights in your model then the default for the fpsandwich and rpsandwich options change from FALSE to TRUE.