# 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)
Run the code above in your browser using DataLab