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
#> 
#>          Term Estimate Std. Error    z Pr(>|z|)   2.5 % 97.5 %    Species
#>  Petal.Length    0.388     0.2602 1.49   0.1360 -0.1220  0.898 setosa    
#>  Petal.Length    0.388     0.2602 1.49   0.1360 -0.1220  0.898 setosa    
#>  Petal.Length    0.374     0.0961 3.89   <0.001  0.1859  0.563 versicolor
#>  Petal.Length    0.374     0.0961 3.89   <0.001  0.1859  0.563 versicolor
#>  Petal.Length    0.374     0.0962 3.89   <0.001  0.1859  0.563 versicolor
#>  Petal.Length    0.234     0.0819 2.86   0.0042  0.0739  0.395 virginica 
#>  Petal.Length    0.234     0.0819 2.86   0.0042  0.0739  0.395 virginica 
#>  Petal.Length    0.234     0.0819 2.86   0.0042  0.0739  0.395 virginica 
#>  Petal.Length    0.234     0.0819 2.86   0.0042  0.0739  0.395 virginica 
#>  Petal.Length
#>          1.00
#>          1.66
#>          3.62
#>          4.28
#>          4.93
#>          4.93
#>          5.59
#>          6.24
#>          6.90
#> 
#> Columns: rowid, term, estimate, std.error, statistic, p.value, conf.low, conf.high, predicted, predicted_hi, predicted_lo, Species, Petal.Length, Sepal.Width 
#>