I want to do some calculations using mixed model regression. I have $n_j$ observations for the $j$-th subject. (The random effect corresponds to the subject.) The problem is that I would like to add weights to the regression so that all the subjects influence equally the result, regardless of the number of observations for each subject. So the wights must be $1/n_j$ for the $j$-th subject. How can I do it in R?
Asked
Active
Viewed 2,081 times
3
-
2https://stat.ethz.ch/pipermail/r-sig-mixed-models/2014q3/022570.html: From Ben Bolker: " I have successfully used weights=varFixed(~I(1/n)) [inverse-variance weighting based on the number of samples per group] in lme; alternatively, you could use weights=n in lmer (from the lme4 package) to get an equivalent result." – mkt Mar 29 '18 at 08:06
-
@mkt Thank you! I was confused with the difference between lm and lme. https://stats.stackexchange.com/questions/70425/weights-argument-in-lm-and-lme-very-different-in-r-am-i-using-them-correctly But I think I am to use `weights=~n`, not `weights=~I(1/n)` in `lme`. Is it so? Yet a bit confused. – Viktor Mar 29 '18 at 12:11
-
Haven't tried it myself, but not what Bolker suggests in that answer. The specific formulation should be easy to figure out in the documentation. – mkt Mar 29 '18 at 14:34
-
a little source code and a toy/dummy data frame would allow an answer with actual code that runs on the dummy data, so you can see if it does what you are wanting. Some folks would say "this is a programming question so it belongs on SE not CV, but that is them. – EngrStudent Jul 25 '19 at 19:38