Skip to content

lme4: Obtaining the SE of difference in two fixed-effects

2 messages · Lenth, Russell V, Ben Bolker

#
Do this:

    a <- c(0, 1, -1)
    V <- vcov(fit)
    sqrt(t(a) %*% V %*% a)

Russ


-----Original Message-----

Message: 2
Date: Wed, 28 Oct 2020 21:29:53 -0500
From: Simon Harmel <sim.harmel at gmail.com>
To: r-sig-mixed-models <r-sig-mixed-models at r-project.org>
Subject: [R-sig-ME] lme4: Obtaining the SE of difference in two
	fixed-effects slope
Message-ID:
	<CACgv6yVbsBJanYRLo4af7P=wUCLQn7RiyhPmE06sSVxNxbdF3Q at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dear All,

I'm interested in obtaining standard error (SE) of [*meanses - ses]* estimate
in my model below which serves as the contextual effect coefficient.

Is there a way to obtain this SE in R?

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
#
Another slightly more automated way to do this is with the 'glht' 
function from multcomp

library(multcomp)
g1 <- glht(fit,linfct=matrix(c(0,1,-1),nrow=1))
(ss <- summary(g1))

	 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|)
1 == 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)

   The 'linfct' argument here is the same as Russ's 'a' vector: it's the 
multiplier for each coefficient in the contrast you want to test.

   ss$sigma will extract the SD from the summary object.
On 10/29/20 9:42 AM, Lenth, Russell V wrote: