Search code examples
rstatisticsregressionlme4multi-level

getting an output for difference of two regression slopes in lme4 package


In my mixed regression model below, I get an output for meanses and an output for ses estimates. Is it also possible to get an output (e.g., Std. Error) for meanses - ses (3.675037 - 2.191165) in this model (I'm open to using any packages)?

library(lme4)

hsb <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')

fit <- lmer(math ~ ses + meanses + (1|sch.id), data = hsb)

coef(summary(fit))

             Estimate Std. Error   t value
(Intercept) 12.661262  0.1493726 84.762956
ses          2.191165  0.1086673 20.163983
meanses      3.675037  0.3776607  9.731055 # can we have `Std. Error` for `meanses - ses`?

Solution

  • Something like this

    > summary(multcomp::glht(fit, "ses - meanses = 0"))
    
         Simultaneous Tests for General Linear Hypotheses
    
    Fit: lmer(formula = math ~ ses + meanses + (1 | sch.id), data = hsb)
    
    Linear Hypotheses:
                       Estimate Std. Error z value Pr(>|z|)    
    ses - meanses == 0   -1.484      0.422  -3.517 0.000437 ***
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    (Adjusted p values reported -- single-step method)