So, it seems to me that the weights function in lm gives observations more weight the larger the associated observation's 'weight' value, while the lme function in lme does precisely the opposite. This can be verified with a simple simulation.
#make 3 vectors- c is used as an uninformative random effect for the lme model
a<-c(1:10)
b<-c(2,4,6,8,10,100,14,16,18,20)
c<-c(1,1,1,1,1,1,1,1,1,1)
If you were now to run a model where you weight the observations based on the inverse of the dependent variable in lm, you can only generate the exact same result in nlme if you weight by just the dependent variable, without taking the inverse.
summary(lm(b~a,weights=1/b))
summary(lme(b~a,random=~1|c,weights=~b))
You can flip this and see the converse is true- specifying weights=b in lm requires weights=1/b to get a matching lme result.
So, I understand this much, I just want validation on one thing and to ask a question about another.
- If I want to weight my data based on the inverse of the dependent variable, is it fine to just code weights=~(dependent variable) within lme?
- Why is lme written to handle weights completely differently than lm? What is the purpose of this other than to generate confusion?
Any insight would be appreciated!
lm()
needed to compatible with S and various books, nlme didn't, and it aimed to be more flexible, allowing the heterogeneity to be modelled more flexibly thanlm
allows. $\endgroup$