# NOT RUN {
# All rows are repeated twice, with different values of `hp`
cd <- counterfactual(data = mtcars, hp = c(100, 110))
cd[cd$rowid %in% 1:3,]
# We get the same result by feeding a model instead of a data.frame
mod <- lm(mpg ~ hp + wt, mtcars)
cd <- counterfactual(model = mod, hp = c(100, 110))
cd[cd$rowid %in% 1:3,]
# Use in `marginaleffects` to compute "Counterfactual Average Marginal Effects"
marginaleffects(mod, newdata = counterfactual(hp = c(100, 110)))
# }
Run the code above in your browser using DataLab