statisticalModeling (version 0.3.0)

fmodel: Plot out model values

Description

Plot out model values

Usage

fmodel(model = NULL, formula = NULL, data = NULL, nlevels = 3, at = list(), prob_of = NULL, intervals = c("none", "confidence", "prediction"), post_transform = NULL, ...)

Arguments

model
the model to display graphically
formula
setting the y ~ x + color variables
data
optional data set from which to extract levels for explanatory variables
nlevels
how many levels to display for those variables shown at discrete levels
at
named list giving specific values at which to hold the variables. You can accomplish this without forming a list by using .... See examples.
prob_of
if to show probability of a given level of the output, name the class here as a character string.
intervals
show confidence or prediction intervals: values "none", "confidence", "prediction"
post_transform
a scalar transformation and new name for the response variable, e.g. post_transform = c(price = exp) to undo a log transformation of price.
...
specific values for explantory variables and/or arguments to predict()

Details

Often you will want to show some data along with the model functions. You can do this with `ggplot2::geom_point()` making sure to set the data argument to be a data frame with the cases you want to plot.

Examples

Run this code
## Not run: 
# mod1 <- lm(wage ~ age * sex + sector, data = mosaicData::CPS85)
# fmodel(mod1)
# fmodel(mod1, ~ sector + sex + age) # not necessarily a good ordering
# # show the data used for fitting along with the model
# fmodel(mod1, ~ age + sex + sector, nlevels = 8) + 
#   ggplot2::geom_point(data = mosaicData::CPS85, alpha = 0.1)
# require(ggplot2)
# fmodel(mod1, ~ age + sex + sector, nlevels = 8) + 
#   geom_point(data = mosaicData::CPS85, alpha = 0.1) +
#   ylim(0, 20)
# mod2 <- lm(log(wage) ~ age + sex + sector, data = mosaicData::CPS85)
# fmodel(mod2, post_transform = c(wage = exp)) # undo the log in the display
# mod3 <- glm(married == "Married" ~ age + sex * sector,
#             data = mosaicData::CPS85, family = "binomial")
# fmodel(mod3, type = "response")
# # Adding the raw data requires an as.numeric() trick when it's TRUE/FALSE
# fmodel(mod3, ~ age + sex + sector, nlevels = 10, type = "response") + 
#   geom_point(data = mosaicData::CPS85, 
#   aes(x = age, y = as.numeric(married == "Married")), alpha = .1)
# ## End(Not run)

Run the code above in your browser using DataLab