Convenience helper for the common case of testing
\(H_0:\, c^\top \beta = 0\) where c is a sparse,
named weight vector. The estimate is \(c^\top \hat\beta\),
the standard error is \(\sqrt{c^\top V c}\) where V
is the model's fixed-effect covariance, the statistic is the Wald
ratio, and the interval is the symmetric Wald CI at level.
Usage
mm_lincomb(fit, weights, level = 0.95, method = NULL, ...)
# Default S3 method
mm_lincomb(fit, weights, level = 0.95, method = NULL, ...)
# S3 method for class 'mm_glmm'
mm_lincomb(fit, weights, level = 0.95, method = NULL, ...)
# S3 method for class 'mm_lmm'
mm_lincomb(
fit,
weights,
level = 0.95,
method = c("auto", "satterthwaite", "kenward_roger", "asymptotic"),
...
)Arguments
- fit
A fitted
mm_lmmormm_glmm.- weights
A named numeric vector (or named list / single-row data.frame coercible to one). Names must match
names(fixef(fit))exactly.- level
Confidence level for the Wald interval. Default 0.95.
- method
For
mm_lmm, the degrees-of-freedom method passed todf_for_contrast(). Defaults to"auto"(Satterthwaite when available). Formm_glmm, only"asymptotic"is accepted.- ...
Reserved for future methods.
Value
A single-row data.frame with columns estimate, std_error,
statistic, statistic_name ("t" or "z"), df, p_value,
lower, upper, and method. The result carries an "mm_status"
attribute reflecting the underlying vcov reliability (status,
method, reliability, reason).
Details
For mm_glmm, the statistic is the asymptotic Wald z (no df). For
mm_lmm, the default is Satterthwaite-approximated t via
df_for_contrast(); pass method = "asymptotic" to force Wald z.
Weight names must be a subset of names(fixef(fit)). Coefficients
not named in weights contribute zero. Pass the long-form
contrast() front door if you need multiple contrasts or non-default
rhs.
See also
contrast() for the long-form, Rust-routed contrast surface
with full estimability / reliability reporting.
Examples
set.seed(1)
d <- data.frame(
g = factor(rep(1:12, each = 8)),
trt = factor(rep(c("ctrl", "drug"), 48)),
x = rnorm(96)
)
d$y <- 1 + 0.5 * (d$trt == "drug") + 0.3 * d$x +
0.4 * (d$trt == "drug") * d$x + rnorm(12)[d$g] + rnorm(96)
fit <- lmm(y ~ trt * x + (1 | g), d, control = mm_control(verbose = -1))
# Treatment effect at x = 1 (weights use lme4 coefficient names):
mm_lincomb(fit, c(trtdrug = 1, "trtdrug:x" = 1))
#> estimate std_error statistic statistic_name df p_value lower
#> 1 0.5599147 0.2773622 2.018713 t 82.68576 0.04675801 0.008221395
#> upper method
#> 1 1.111608 satterthwaite