Estimate the slopes (i.e., the coefficient) of a predictor over different factor levels or alongside a numeric variable. See also other related functions such as estimate_contrasts and estimate_means.

estimate_slopes(
  model,
  trend = NULL,
  levels = NULL,
  modulate = NULL,
  ci = 0.95,
  ...
)

Arguments

model

A statistical model.

trend

A character vector indicating the name of the numeric variable for which to compute the slopes.

levels

A character vector or formula specifying the names of the factors over which levels to estimate the means, contrasts or slopes. If NULL (default), will automatically try to find it.

modulate

A character vector indicating the names of a numeric variable along which the means or the contrasts will be estimated. Other arguments from visualisation_matrix, such as length to adjust the number of data points.

ci

Confidence Interval (CI) level. Default to 0.95 (95%).

...

Other arguments passed for instance to visualisation_matrix.

Value

A data.frame.

Examples

model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)
slopes <- estimate_slopes(model, trend = "Petal.Length", levels = "Species")
slopes
#> Estimated Marginal Effects
#> 
#> Species    | Coefficient |   SE |        95% CI | t(144) |      p
#> -----------------------------------------------------------------
#> setosa     |        0.39 | 0.26 | [-0.13, 0.90] |   1.49 | 0.138 
#> versicolor |        0.37 | 0.10 | [ 0.18, 0.56] |   3.89 | < .001
#> virginica  |        0.23 | 0.08 | [ 0.07, 0.40] |   2.86 | 0.005 
#> Marginal effects estimated for Petal.Length
plot(slopes)

effectsize::standardize(slopes)
#> Estimated Marginal Effects (standardized)
#> 
#> Species    | Coefficient |   SE |        95% CI | t(144) |      p
#> -----------------------------------------------------------------
#> setosa     |        0.89 | 0.60 | [-0.29, 2.07] |   1.49 | 0.138 
#> versicolor |        0.86 | 0.22 | [ 0.42, 1.29] |   3.89 | < .001
#> virginica  |        0.54 | 0.19 | [ 0.17, 0.91] |   2.86 | 0.005 
#> Marginal effects estimated for Petal.Length

if (require("mgcv")) {
  model <- mgcv::gam(Sepal.Width ~ s(Petal.Length), data = iris)
  slopes <- estimate_slopes(model, modulate = "Petal.Length", length = 30)
  summary(slopes)
  plot(slopes)
}
#> Loading required package: mgcv
#> Loading required package: nlme
#> 
#> Attaching package: ‘nlme’
#> The following object is masked from ‘package:lme4’:
#> 
#>     lmList
#> This is mgcv 1.8-35. For overview type 'help("mgcv-package")'.
#> No numeric variable was specified for slope estimation. Selecting `trend = "Petal.Length"`.