Skip to contents

Modelbased-like API to create marginaleffects objects. This is Work-in-progress.

Usage

get_marginaleffects(
  model,
  trend = NULL,
  by = NULL,
  fixed = NULL,
  at = NULL,
  ...
)

Arguments

model

A statistical model.

trend

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

by

The predictor variable(s) at which to evaluate the desired effect / mean / contrasts. Other predictors of the model that are not included here will be collapsed and "averaged" over (the effect will be estimated across them).

fixed

A character vector indicating the names of the predictors to be "fixed" (i.e., maintained), so that the estimation is made at these values.

at

Deprecated, use by instead.

...

Other arguments passed for instance to insight::get_datagrid().

Examples

if (require("marginaleffects")) {
  model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)

  get_marginaleffects(model, trend = "Petal.Length", by = "Species")
  get_marginaleffects(model, trend = "Petal.Length", by = "Petal.Length")
  get_marginaleffects(model, trend = "Petal.Length", by = c("Species", "Petal.Length"))
}
#> Loading required package: marginaleffects
#> 
#>     Species Estimate Std. Error    z Pr(>|z|)    S   2.5 % 97.5 %
#>  setosa        0.388     0.2602 1.49  0.13601  2.9 -0.1221  0.898
#>  setosa        0.388     0.2601 1.49  0.13596  2.9 -0.1220  0.898
#>  versicolor    0.374     0.0963 3.89  < 0.001 13.3  0.1856  0.563
#>  versicolor    0.374     0.0963 3.89  < 0.001 13.3  0.1856  0.563
#>  versicolor    0.374     0.0963 3.89  < 0.001 13.3  0.1856  0.563
#>  virginica     0.234     0.0819 2.86  0.00420  7.9  0.0739  0.395
#>  virginica     0.234     0.0819 2.86  0.00421  7.9  0.0739  0.395
#>  virginica     0.234     0.0818 2.86  0.00418  7.9  0.0740  0.395
#>  virginica     0.234     0.0819 2.86  0.00420  7.9  0.0739  0.395
#> 
#> Term: Petal.Length
#> Type:  response 
#> Columns: rowid, term, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted, Species, Petal.Length, Sepal.Width 
#>