Specifying weight in R2MLwiN
-
- Posts: 30
- Joined: Tue Apr 12, 2016 10:54 am
Specifying weight in R2MLwiN
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
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
-
- Posts: 1384
- Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying weight in R2MLwiN
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:
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
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:
However, I get the following error
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)
/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
-
- Posts: 1384
- Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying weight in R2MLwiN
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
When I enter debugmode I discover that Mlwin crashes. I tried varying the following arguments, but it still crashes:Could you try adding the debugmode=TRUE option and then checking within the MLwiN interface whether any errors are reported?
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)
-
- Posts: 30
- Joined: Tue Apr 12, 2016 10:54 am
Re: Specifying weight in R2MLwiN
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
http://www.bristol.ac.uk/cmm/software/r2mlwin/
Vivian
Code: Select all
library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
Vivian
-
- Posts: 1384
- Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying weight in R2MLwiN
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
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:
On a related note. I wonder how rp- and fpsandwish works for weighting? The manual states:
I know that rp- and fpsanwish swith on sandwiched SE, but how does that relate to weighting (e.g. using case specific sample weights)?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
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.
-
- Posts: 1384
- Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying weight in R2MLwiN
If you specify weights in your model then the default for the fpsandwich and rpsandwich options change from FALSE to TRUE.