pm_slopes: Slopes of a Covariate by Group

View source: R/pm_slopes.R

pm_slopesR Documentation

Slopes of a Covariate by Group

Description

The slope (rate of change) of the fitted response in a numeric covariate within each level of a model term, with standard errors, degrees of freedom, confidence limits and tests, and pairwise comparisons of the slopes, as emmeans::emtrends() and SAS ESTIMATE statements on slope terms.

Usage

pm_slopes(model, covariate, modelterm, at = NULL, conf_level = 0.95, adj = "none",
          df_method = c("auto", "Kenward-Roger", "Satterthwaite", "containment",
            "between-within", "KR-expected", "KR-average", "inner-outer", "residual"),
          vcov_adjust = TRUE,
          weights = c("equal", "proportional", "outer", "cells", "flat"),
          vcov = NULL, ...)

Arguments

model

A fitted model, as for predictmeans.

covariate

Name (in "quotes") of the numeric covariate.

modelterm

Name (in "quotes") of the factor term whose levels get a slope each, e.g. "Variety".

at

The value of the covariate where the slopes are taken (matters only when the covariate enters the model non-linearly); the default is its mean.

conf_level

Confidence level of the limits, the default is 0.95 (level = 0.05 before 2.0).

adj

Adjustment of the p-values of the pairwise comparisons of slopes, as in predictmeans.

df_method, vcov_adjust, weights, vcov

As in predictmeans.

...

Not used: level (before 2.0) stops with its 2.0 spelling.

Details

The slopes are on the scale of the linear predictor. They come from the reference grid of Kmatrix: the change in the K matrix between at - h and at + h, divided by 2h with h = 0.0001 times the standard deviation of the covariate. This is exact when the covariate enters the model linearly (also through interactions) and a central difference for poly(), splines and smooths, whose slope depends on at. Standard errors and degrees of freedom follow predictmeans: for models fitted by REML (lmer, lme, gls) Kenward-Roger (with the adjusted covariance when vcov_adjust = TRUE); with one df per term (containment, between-within, nlme's df) the smallest df of the terms with the covariate; otherwise the residual df.

Value

An object of class "pm_slopes", a list in the layout of predictmeans (tidy() and as.data.frame() return its tables, what = "slopes" or "pairs"):

slopes

one row per level of modelterm: the factor columns, estimate (the slope), std.error, df, statistic (t), p.value (of slope = 0), conf.low and conf.high.

pairs

one row per pair of levels: level1, level2, estimate (slope of level1 minus slope of level2), std.error, df, statistic, p.value, p.adj, conf.low, conf.high and, with the adjustments that have them (tukey, bonferroni, sidak, scheffe, mvt), adj.conf.low, adj.conf.high: simultaneous limits that leave out 0 exactly when p.adj is below 1 - conf_level.

settings

modelterm, covariate, at, level, adjust, df_method, vcov_adjust, vcov, model_class, version.

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

See Also

covariatemeans, predictmeans, advice

Examples

  library(predictmeans)
  Oats <- as.data.frame(nlme::Oats)
  fm <- lmer(yield ~ nitro*Variety + (1|Block/Variety), data = Oats)
  sl <- pm_slopes(fm, "nitro", "Variety", adj = "tukey")
  sl
  as.data.frame(sl, what = "pairs")

predictmeans documentation built on Nov. 24, 2026, 5:10 p.m.