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
#> 
#>          Term    Species Petal.Length Estimate Std. Error    z Pr(>|z|)    S
#>  Petal.Length setosa             1.00    0.388     0.2602 1.49  0.13601  2.9
#>  Petal.Length setosa             1.66    0.388     0.2601 1.49  0.13596  2.9
#>  Petal.Length versicolor         3.62    0.374     0.0963 3.89  < 0.001 13.3
#>  Petal.Length versicolor         4.28    0.374     0.0963 3.89  < 0.001 13.3
#>  Petal.Length versicolor         4.93    0.374     0.0963 3.89  < 0.001 13.3
#>  Petal.Length virginica          4.93    0.234     0.0819 2.86  0.00420  7.9
#>  Petal.Length virginica          5.59    0.234     0.0819 2.86  0.00421  7.9
#>  Petal.Length virginica          6.24    0.234     0.0818 2.86  0.00418  7.9
#>  Petal.Length virginica          6.90    0.234     0.0819 2.86  0.00420  7.9
#>    2.5 % 97.5 %
#>  -0.1221  0.898
#>  -0.1220  0.898
#>   0.1856  0.563
#>   0.1856  0.563
#>   0.1856  0.563
#>   0.0739  0.395
#>   0.0739  0.395
#>   0.0740  0.395
#>   0.0739  0.395
#> 
#> 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 
#> Type:  response 
#>