Anova with unequal variances via regression modeling I would like to fit a one-way between-subject anova that assumes unequal variances between groups.
Reproducible example:
library(emmeans)
library(car)

set.seed(123)
n <- 50
DF <- data.frame(score = c(rnorm(n, sd = 10), rnorm(n, sd = 30), rnorm(n, sd = 40)),
                 treatment = rep(c("A", "B", "C"), each = n),
                 subject = 1:(n*3))

leveneTest(score ~ treatment, DF) # Shows heterogeneity of variance

mdl <- lm(score ~ treatment, data = DF)
emmeans(mdl, ~treatment) # same SE for all the means
# treatment  emmean   SE  df lower.CL upper.CL
# A           0.344 3.99 147    -7.54     8.23
# B           4.392 3.99 147    -3.50    12.28
# C         -10.156 3.99 147   -18.04    -2.27
# Confidence level used: 0.95 

Is there a way to tweak lm (or lmer) to take into account unequal variance?

Found a way to do it via lmer:
library(lme4)

mdl <- lmer(score ~ treatment + (0 + treatment|subject), data = DF,
              + control = lmerControl(check.nobs.vs.nRE = "ignore", 
                                      check.nobs.vs.nlev = "ignore"))
#Warning messages:
#  1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
#  unable to evaluate scaled gradient
#  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
#  Model failed to converge: degenerate  Hessian with 3 negative eigenvalues

emmeans(mdl, ~ treatment)
# treatment  emmean   SE df lower.CL upper.CL
# A           0.344 1.31 49    -2.29     2.98
# B           4.392 3.84 49    -3.33    12.11
# C         -10.156 5.60 49   -21.40     1.09
# Degrees-of-freedom method: kenward-roger 
# Confidence level used: 0.95   

