# Why the confidence intervals in a categorical lm() are not calculated at the group level?

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"))) 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.

• 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. – Frans Rodenburg Dec 23 '20 at 21:18

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.