Hi all,

Could you please help me?

I am trying to replicate the weighted LMM in LME4 lmer function with the
weights option myself:

The data is located at:

http://www.ling.uni-potsdam.de/~vasishth/book.html

In the section:

downloadable errata, code, datasets
•ERRATA
•Corrected Pages
•VasishthBroebook.R
•beauty.txt
•mathachieve.txt
•mathachschool.txt


And here is my code:

Basically, I want to replicate the weighted LMM myself and see if my
understanding of lmer is correct:

Could you please take a look for me?

I checked a few cases, my result "lme6x" and the weighted lmer result
"lme6" seem to match.

However, the numerical difference is about 0.0001221494, so I am not sure
about:

a) whether my replication can work for all possible cases;
b) are there better(more accurate and more elegant) way of doing the
weighted LMM myself?


Thank you!

----------------------------------

MathAchieve <- read.table("mathachieve.txt")

colnames(MathAchieve) <- c("School", "Minority", "Sex", "SES",  "MathAch",
"MEANSES")

MathAchSchool <- read.table("mathachschool.txt")

colnames(MathAchSchool) <- c("School", "Size", "Sector", "PRACAD",
"DISCLIM", "HIMINTY", "MEANSES")

MathScores <- merge(MathAchieve, MathAchSchool, by = "School")


w=1:dim(MathScores)[1]
sw=sqrt(w)

lme6 = lmer(MathAch ~ SES  + factor(Sector)+  (1 + SES |School)  +  (1 +
SES |Sector) , MathScores, weights=w)

X=model.matrix(MathAch ~ SES+factor(Sector) , MathScores)
y=MathScores$MathAch
X=X*sw
y=y*sw
tmp=cbind(MathScores, sw)
names(tmp)[length(names(tmp))]="Intercept"
tmp[["SES"]]=tmp[["SES"]]*sw
lme6x = lmer(Y~X-1+ (Intercept - 1 + SES | School)+ (Intercept - 1 + SES |
Sector), tmp)



max(abs(fitted(lme6) - fitted(lme6x)/sw))



> max(abs(fitted(lme6) - fitted(lme6x)/sw))
[1] 0.0001221494

	[[alternative HTML version deleted]]

