Description Usage Arguments Details Value Examples
View source: R/marginalmeans.R
Compute estimated marginal means for specified factors.
1 2 3 4 5 6 7  marginalmeans(
model,
variables = NULL,
variables_grid = NULL,
vcov = insight::get_varcov(model),
type = "response"
)

model 
Model object 
variables 
Categorical predictors over which to compute marginal means
(character vector). 
variables_grid 
Categorical predictors used to construct the
prediction grid over which adjusted predictions are averaged (character
vector). 
vcov 
Matrix or boolean

type 
Type(s) of prediction as string or vector This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero". 
This function begins by calling the predictions
function to obtain a
grid of predictors, and adjusted predictions for each cell. The grid
includes all combinations of the categorical variables listed in the
variables
and variables_grid
arguments, or all combinations of the
categorical variables used to fit the model if variables_grid
is NULL
.
In the prediction grid, numeric variables are held at their means.
After constructing the grid and filling the grid with adjusted predictions,
marginalmeans
computes marginal means for the variables listed in the
variables
argument, by average across all categories in the grid.
marginalmeans
can only compute standard errors for linear models, or for
predictions on the link scale, that is, with the type
argument set to
"link".
The marginaleffects
website compares the output of this function to the
popular emmeans
package, which provides similar but more advanced
functionality: https://vincentarelbundock.github.io/marginaleffects/
Data frame of marginal means with one row per variablevalue combination.
1 2 3 4 5 6 7 8 9 10 11  library(marginaleffects)
# Convert numeric variables to categorical before fitting the model
dat < mtcars
dat$cyl < as.factor(dat$cyl)
dat$am < as.logical(dat$am)
mod < lm(mpg ~ hp + cyl + am, data = dat)
# Compute and summarize marginal means
mm < marginalmeans(mod)
summary(mm)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.