Hi all,
I was wondering if there is a way to specify sampling weights in a multi-group model? I want all observations in a certain group to be weighed equally, but groups with a larger weight should have more influence on the estimation of parameters that are shared/equal between groups.
Best,
Manuel
Hi Manuel,
There's nothing special you need to do here. Just specify the weights in the
mxData()
for each group. The weights will happen to be the same for all rows within a group, and different for different groups, but there's nothing special that needs to happen withmxFitFunctionMultigroup()
.Specify the data in each group with
mxData(..., weight='someWeight')
. The data will look likeHope that helps!
Hi Mike,
thanks for your reply! I had tried that argument, but my R crashed repeatedly ("R Session aborted"). It is quite curious, I now tried it again and got this error message: "MxExpectationStateSpace: row frequencies or weights provided in 'person 1.data' are not supported". I then ran the script again without making changes to it, and it crashed again. I can't figure out why it crashes most of the time. In about 10 tries I saw the error only twice, the rest of the time the R Session aborted.
Ahh. Well, R shouldn't be crashing in this case. But the error message is correct: we do not currently support sample weights or row frequencies for state space models. The math should work the same as for other models, but I just don't know what it would mean. I've created an issue on GitHub to resolve the crashing problem, but I do not plan to implement this feature.
You can do what you need with an
mxFitFunctionAlgebra()
instead of anmxFitFunctionMultigroup()
. It would look something like thisIf you have a large number of groups you can use
mxAlgebraFromString()
.Yes, I also found the mxFitFunctionAlgebra() function earlier today and it seems to be exactly what I need. I've been doing some tests and it works well so far.
Thanks for the advice on using mxAlgebraFromString()! I used eval(parse(...)) to turn my string into an object, but this seems easier.
Hi Manuel
Could you please provide a script that crashes R, including any data that it needs? We all hate it when R crashes, and it is almost certainly a bug, which we would like to repair.
Cheers
Mike
I already made a script that replicates the crash.