5
$\begingroup$

This is probably very easy but I could not find a straightforward answer.

reproducible example

y1<-c(rnorm(5,10,5),rnorm(5,1,0.1),rnorm(5,1,0.1))
x1<-c(rep("a",5),rep("b",5), rep("c",5) )
set.seed(12)
datap<-data.frame(y1,x1)
mod1<-lm(y1 ~ x1, data = datap)
summary(mod1)

plot(y1~x1 ,data=datap)

da <- as.data.frame(summary(emmeans(mod1,spec="x1")))

enter image description here

I would expect the confidence intervals for the group "b" and "c" to be much smaller than group "a" but they are all the same size. Why? Is it possible to represent a more "realistic" variance?

Sorry for the silly question.

$\endgroup$
1
  • $\begingroup$ Dave's answer is great, but I just want to add that if you have data where higher mean values have greater variance, like in your MWE, then often a logarithmic transformation is appropriate. $\endgroup$ – Frans Rodenburg Dec 23 '20 at 21:18
8
$\begingroup$

The lm function does its inferential work under a fairly standard assumption that the error term has constant variance. That appears to be a poor assumption for your data, but lm does not know that, so it just treats the groups as having equal variance and calculates the error term variance thinking it is the same for each group.

Weighted least squares is one approach to getting a different variance for each group.

$\endgroup$
1
  • 3
    $\begingroup$ See the FAQs vignette in the emmeans package. $\endgroup$ – Russ Lenth Dec 23 '20 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.