Skip to contents

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

Usage

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

Arguments

model

A statistical model.

trend

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

at

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.

...

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", at = "Species")
  get_marginaleffects(model, trend = "Petal.Length", at = "Petal.Length")
  get_marginaleffects(model, trend = "Petal.Length", at = c("Species", "Petal.Length"))
}
#> Loading required package: marginaleffects
#>   rowid     type         term      dydx  std.error statistic      p.value
#> 1     1 response Petal.Length 0.3878739 0.26016781  1.490860 1.359982e-01
#> 2     2 response Petal.Length 0.3878739 0.26016781  1.490860 1.359982e-01
#> 3     3 response Petal.Length 0.3743068 0.09614966  3.892961 9.902820e-05
#> 4     4 response Petal.Length 0.3743068 0.09614966  3.892960 9.902831e-05
#> 5     5 response Petal.Length 0.3743068 0.09614966  3.892961 9.902823e-05
#> 6     6 response Petal.Length 0.2343482 0.08186666  2.862559 4.202344e-03
#> 7     7 response Petal.Length 0.2343482 0.08186667  2.862559 4.202345e-03
#> 8     8 response Petal.Length 0.2343482 0.08186667  2.862559 4.202346e-03
#> 9     9 response Petal.Length 0.2343482 0.08186667  2.862559 4.202346e-03
#>      conf.low conf.high Petal.Length    Species
#> 1 -0.12204567 0.8977934     1.000000     setosa
#> 2 -0.12204566 0.8977934     1.655556     setosa
#> 3  0.18585697 0.5627567     3.622222 versicolor
#> 4  0.18585696 0.5627567     4.277778 versicolor
#> 5  0.18585697 0.5627567     4.933333 versicolor
#> 6  0.07389248 0.3948039     4.933333  virginica
#> 7  0.07389248 0.3948039     5.588889  virginica
#> 8  0.07389247 0.3948039     6.244444  virginica
#> 9  0.07389247 0.3948039     6.900000  virginica