get_datagrid.emmGrid: Extract a reference grid from objects created by '{emmeans}'...

View source: R/get_datagrid.R

get_datagrid.emmGridR Documentation

Extract a reference grid from objects created by {emmeans} and {marginaleffects}

Description

Extract a reference grid from objects created by {emmeans} and {marginaleffects}

Usage

## S3 method for class 'emmGrid'
get_datagrid(x, ...)

Arguments

x

An object created by a function such as emmeans::emmeans(), marginaleffects::slopes(), etc.

...

Currently not used

Details

Note that for {emmeans} inputs the results is a proper grid (all combinations of values are represented), except when a nesting structure is detected. Additionally, when the input is an emm_list object, the function will rbind() the data-grids of all the elements in the input.

For {marginaleffects} inputs, the output may very well be a non-grid result. See examples.

Value

A data.frame with key columns that identify the rows in x.

Examples

data("mtcars")
mtcars$cyl <- factor(mtcars$cyl)

mod <- glm(am ~ cyl + hp + wt,
  family = binomial("logit"),
  data = mtcars
)


em1 <- emmeans::emmeans(mod, ~ cyl + hp, at = list(hp = c(100, 150)))
get_datagrid(em1)

contr1 <- emmeans::contrast(em1, method = "consec", by = "hp")
get_datagrid(contr1)

eml1 <- emmeans::emmeans(mod, pairwise ~ cyl | hp, at = list(hp = c(100, 150)))
get_datagrid(eml1) # not a "true" grid


mfx1 <- marginaleffects::slopes(mod, variables = "hp")
get_datagrid(mfx1) # not a "true" grid

mfx2 <- marginaleffects::slopes(mod, variables = c("hp", "wt"), by = "am")
get_datagrid(mfx2)

contr2 <- marginaleffects::avg_comparisons(mod)
get_datagrid(contr2) # not a "true" grid


easystats/insight documentation built on Dec. 14, 2024, 12:34 p.m.