get_marginalmeans: Easy 'avg_predictions' and 'avg_slopes'

View source: R/get_marginalmeans.R

get_marginalcontrastsR Documentation

Easy 'avg_predictions' and 'avg_slopes'

Description

The get_marginalmeans() function is a wrapper to facilitate the usage of marginaleffects::avg_predictions() and marginaleffects::avg_slopes(), providing a somewhat simpler and intuitive API to find the specifications and variables of interest. It is meanly made to for the developers to facilitate the organization and debugging, and end-users should rather use the ⁠estimate_*()⁠ series of functions.

Usage

get_marginalcontrasts(model, by = NULL, ci = 0.95, method = "pairwise", ...)

model_marginalcontrasts(model, by = NULL, ci = 0.95, method = "pairwise", ...)

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

get_marginalmeans(model, by = "auto", transform = NULL, ci = 0.95, ...)

model_marginalmeans(model, by = "auto", transform = NULL, ci = 0.95, ...)

Arguments

model

A statistical model.

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).

ci

Level for confidence intervals.

method

Contrast method.

...

Other arguments passed, for instance, to insight::get_datagrid() or marginaleffects::avg_predictions().

trend

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

transform

Can be used to easily modulate the type argument in marginaleffects::avg_predictions(). Can be "none" or "response". "none" will leave the values on scale of the linear predictors. "response" will transform them on scale of the response variable. Thus for a logistic model, "none" will give estimations expressed in log-odds (probabilities on logit scale) and "response" in terms of probabilities.

Examples


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"))


model <- lm(Sepal.Length ~ Species + Petal.Width, data = iris)

# By default, 'by' is set to "Species"
get_marginalmeans(model)

# Overall mean (close to 'mean(iris$Sepal.Length)')
get_marginalmeans(model, by = NULL)

# One can estimate marginal means at several values of a 'modulate' variable
get_marginalmeans(model, by = "Petal.Width", length = 3)

# Interactions
model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)

get_marginalmeans(model)
get_marginalmeans(model, by = c("Species", "Petal.Length"), length = 2)
get_marginalmeans(model, by = c("Species", "Petal.Length = c(1, 3, 5)"), length = 2)


easystats/estimate documentation built on Dec. 18, 2024, 4:41 p.m.