[R-sig-ME] lmer(): Higher weight in case of more measurements

Susanne Susanne susanne.stat at gmx.de
Wed Jun 24 15:10:41 CEST 2015


Hello everyone,
 
I just saw now, that my last emails were empty. I had this question regarding the lme4 package. 
I want to  regress a simple
 
  lmer(y ~ x + (x | group),

but the number of datapoints vary among groups.
 
So what I want is to weight groups, which have more measurements than others, slightly higher (as they provide more information).

 
My question is: Is this done automatically in the lmer() function or should I do it manually by myself?


It seems an easy question, but I tried a small example which I attached and it's very contradictory.

The upper two pictures seem to proove that lmer doesn't weight groups higher which report more datapoints. I get the same regression line, independent of whether the blue group has more or less datapoints.

In the lower two pictures I used the "weights=" argument to weight the blue group higher. And then suddenly it seems to matter how many datapoints a group has. I used the same weights in both pictures, but now I get different regression lines, dependent of how many datapoints the blue group has. 
  

I really need to know this for my thesis and would be very thankful if someone could help me!

Susanne
 

 

I add my code:

# Data 
# many Values 
x <- c(2, 4, 1, 1.25, 1.5,1.75, 2,2.25, 2.5, 2.75, 3, 3.25, 3.5,3.75,4,4.25, 4.5, 4.75, 5) 
y <- c(0.2, 0.4, 0.5, 0.525, 0.57, 0.575, 0.62, 0.625, 0.65, 0.677, 0.7,0.726,0.75,0.775,0.8,0.827,0.85,0.873, 0.9) 
group <- c(1,1,rep(2,17)) 

# Less values 
x <- c(2, 4, 1, 3.25, 5) y <- c(0.2, 0.4,0.5,0.726, 0.9) 
group <- c(1,1,rep(2,3)) 

# Weights 
if(weights == "Default"){ w <- NULL } 

if(weights == "Disequilibrated"){
   w <- c(1,1, rep(5000,17)) 
  # or for less values 
  w <- c(1,1, rep(5000,3)) 
  # scale weights to sum weights=number of values 
  w <- length(w)*w/sum(w) } 

# Lme Model 
lmeModel <- lmer(y ~ x + (x|group), weights=w) 
s <- summary(lmeModel) 

# Plot 
plot(x,y, pch=16, col=c(1,1,rep(2,17)), xlim=c(min(x),max(x)),ylim=c(min(y),max(y)), ylab="y",xlab="x",main="Random Intercept + Slope") abline(s$coefficients[1,1],s$coefficients[2,1], lty=2, col = 1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: Plots.png
Type: image/png
Size: 52978 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20150624/7151476b/attachment-0001.png>


More information about the R-sig-mixed-models mailing list