Learn R Programming

polywog (version 0.4-1)

plot.polywog: Univariate and bivariate fitted value plots

Description

Generates plots of the relationship between input variables and the expected value of the outcome, using predVals as a backend.

Usage

# S3 method for polywog
plot(x, which = NULL, ask = FALSE, auto.set.par = TRUE,
  interval = TRUE, level = 0.95, FUN3D = c("contour", "filled.contour",
  "wireframe", "persp3d"), control.plot = list(), ...)

Arguments

x

a fitted model of class "polywog", typically the output of polywog.

which

selection of variables to plot: a character vector containing one or two names of raw input variables (see x$varNames). May also be a numeric vector corresponding to indices of x$varNames. If which = NULL, a plot of each individual term will be generated.

ask

logical: whether to display an interactive menu of terms to select.

auto.set.par

logical: whether to temporarily change the graphics parameters so that multiple plots are displayed in one window (e.g., each univariate plot when which = NULL).

interval

logical: whether to display bootstrap confidence intervals around each fitted value. Not available for bivariate plots unless FUN3d = "persp3d".

level

confidence level for the intervals.

FUN3D

which plotting function to use to generate bivariate plots. Valid options include "contour" (the default) and "filled.contour"; "wireframe", which requires the lattice package; and "persp3d", which requires the rgl package.

control.plot

list of arguments to be passed to the underlying plotting functions (e.g., axis labels and limits).

...

additional arguments to be passed to predVals.

Value

An object of class preplot.polywog, invisibly. This is a data frame generated by predVals that contains all information used in plotting.

Details

By default, a univariate plot generated by plot.polywog shows the relationship between the selected input variable and the expected outcome while holding all other covariates at "central" values (as in predVals). The values that the other variables are held out can be changed by supplying additional arguments to ..., as in the examples below.

Similarly, a bivariate plot shows the relationship between two input variables and the expected outcome while holding all else fixed. If either variable is binary or categorical, the plot will show the relationship between one variable and the expected outcome across each value/level of the other.

Examples

Run this code
# NOT RUN {
## Using occupational prestige data
data(Prestige, package = "carData")
Prestige <- transform(Prestige, income = income / 1000)

## Fit a polywog model with bootstrap iterations
## (note: using low convergence threshold to shorten computation time of the
## example, *not* recommended in practice!)
set.seed(22)
fit1 <- polywog(prestige ~ education + income + type,
                data = Prestige,
                degree = 2,
                boot = 5,
                thresh = 1e-4)

## All univariate relationships
plot(fit1, n = 20)

## Predicted prestige across occupational categories
plot(fit1, which = "type",
     control.plot = list(xlab = "occupational category"))

## Predicted prestige by education across occupational categories
plot(fit1, which = c("education", "type"), n = 20)

## Joint effect of education and income
plot(fit1, which = c("education", "income"), n = 10)

## Bring up interactive menu
# }
# NOT RUN {
plot(fit1, ask = TRUE)

  # displays menu:
  # Select one or two variable numbers (separated by spaces), or 0 to exit:

  # 1: education
  # 2: income
  # 3: type
# }

Run the code above in your browser using DataLab