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?

You can do heterogeneous variance in a variety of ways in R. A simple way is through the gls package
library(nlme)
mod = gls(score~treatment, data=DF, 
          weights = varIdent(form = ~1|treatment), 
              method="ML")
emmeans(mod, ~treatment) 

although lme4 is more efficient and popular, nlme offers a variety of structures for the residuals. Of course you can always go the Bayesian route if you need even more flexibility
library(brms)
modb <- brm(
     bf(score ~ treatment,
        sigma ~ treatment), 
      family = gaussian,
      data=DF)
emmeans(modb, ~ treatment)

