R/mod_eval_grid.R
mod_eval_grid.RdThis function tries to choose sensible values of the explanatory variables
from the data used to build a model or any other specified data.
(or from data specified with the data = argument.)
mod_eval_grid(mod, formula = NULL, nlevels = 3, pretty = TRUE, npts = 100, ...)
| mod | either a data frame or a model from which to extract the data to be discretized. If a model is given, then the model output will be appended for all rows. |
|---|---|
| formula | a formula with one variable to identify a variable to be sampled finely (npts over the range) |
| nlevels | the number of discrete levels to use, by default |
| pretty | if TRUE, make the discretized versions of numerical values sensibly spaced for viewing |
| npts | the number of points to evaluate the variable identified by formula (default: 100) |
| ... | a more concise mechanism to passing desired values for variables |
A dataframe containing all combinations of the selected values for
the explanatory variables. If there are p explanatory variables,
there will be about nlevels^p cases.
For categorical variables, the most populated levels are used. For quantitative
variables, a sequence of pretty() values is generated.
For categorical variables, will return the nlevels most popular levels, unless
the levels are specified explicitly in an argument. When the model is a classifier, the model outputs will
be the probabilities of each level in the response variable. These will be named prob_[level].
Using pretty = TRUE may cause the number of levels for quantitative variables to be somewhat different
from nlevels.
# NOT RUN { mod1 <- lm(wage ~ age * sex + sector, data = mosaicData::CPS85) for_plotting <- mod_eval_grid(mod1, ~ age, nlevels = Inf) gf_line(model_output ~ age | sector, color = ~ sex, data = for_plotting ) for_plotting2 <- mod_eval_grid(mod1, ~ age, sector = c("const", "service")) gf_line(model_output ~ age | sector, color = ~ sex, data = for_plotting2 ) # }