datagridcf | R Documentation |
datagrid()
function.For each combination of the variable values specified, this function
duplicates the entire data frame supplied to newdata
, or the entire
dataset used to fit model
. This is a convenience shortcut to call the
datagrid()
function with argument grid_type="counterfactual"
.
datagridcf(..., model = NULL, newdata = NULL)
... |
named arguments with vectors of values or functions for user-specified variables.
|
model |
Model object |
newdata |
data.frame (one and only one of the |
Other grid:
datagrid()
# Fit a model with 32 observations from the `mtcars` dataset. nrow(mtcars) mod <- lm(mpg ~ hp + am, data = mtcars) # We specify two values for the `am` variable and obtain a counterfactual # dataset with 64 observations (32 x 2). dat <- datagridcf(model = mod, am = 0:1) head(dat) nrow(dat) # We specify 2 values for the `am` variable and 3 values for the `hp` variable # and obtained a dataset with 192 observations (2x3x32), corresponding to the # full original data, with each possible combination of `hp` and `am`. dat <- datagridcf(am = 0:1, hp = c(100, 110, 120), newdata = mtcars) head(dat) dim(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.