Learn R Programming

perry (version 0.3.1)

setupPerryPlot: Set up a plot of resampling-based prediction error results

Description

Extract and prepare the relevant information for a plot of results of resampling-based prediction error measures.

Usage

setupPerryPlot(object, ...)

# S3 method for perry setupPerryPlot( object, which = c("box", "density", "dot"), select = NULL, seFactor = NA, ... )

# S3 method for perrySelect setupPerryPlot( object, which = c("box", "density", "dot", "line"), subset = NULL, select = NULL, seFactor = object$seFactor, ... )

# S3 method for perryTuning setupPerryPlot(object, ...)

Arguments

object

an object inheriting from class "perry" or "perrySelect" that contains prediction error results.

for the "perryTuning" method, additional arguments to be passed down to the "perrySelect" method. For the other methods, additional arguments are currently ignored.

which

a character string specifying the type of plot to prepare. Possible values are "box" to prepare a box plot, "density" to prepare a smooth density plot, "dot" to prepare a dot plot, or "line" to prepare a plot of the (average) results for each model as a connected line (for objects inheriting from class "perrySelect"). Note that the first two plots are only meaningful in case of repeated resampling. The default is to use "box" in case of repeated resampling and "dot" otherwise.

select

a character, integer or logical vector indicating the columns of prediction error results to be prepared for plotting.

seFactor

a numeric value giving the multiplication factor of the standard error for displaying error bars in dot plots or line plots. Error bars in those plots can be suppressed by setting this to NA.

subset

a character, integer or logical vector indicating the subset of models to be prepared for plotting.

Value

An object of class "setupPerryPlot" with the following components:

data

a data frame containing the following columns:

Fit

a vector or factor containing the identifiers of the models.

Name

a factor containing the names of the predictor error results (not returned in case of only one column of prediction error results with the default name).

PE

the estimated prediction errors.

Lower

the lower end points of the error bars (only returned if possible to compute).

Upper

the upper end points of the error bars (only returned if possible to compute).

which

a character string specifying the type of plot.

grouped

a logical indicating whether density plots should be grouped due to multiple model fits (only returned in case of density plots for the "perrySelect" and "perryTuning" methods).

includeSE

a logical indicating whether error bars based on standard errors are available (only returned in case of dot plots or line plots).

mapping

default aesthetic mapping for the plots.

facets

default faceting formula for the plots (not returned in case of only one column of prediction error results with the default name).

tuning

a data frame containing the grid of tuning parameter values for which the prediction error was estimated (only returned for the "perryTuning" method).

See Also

perryPlot,

perryFit, perrySelect, perryTuning,

ggplot, autoplot, plot

Examples

Run this code
# NOT RUN {
library("perryExamples")
data("coleman")
set.seed(1234)  # set seed for reproducibility

## set up folds for cross-validation
folds <- cvFolds(nrow(coleman), K = 5, R = 10)

## compare LS, MM and LTS regression

# perform cross-validation for an LS regression model
fitLm <- lm(Y ~ ., data = coleman)
cvLm <- perry(fitLm, splits = folds,
              cost = rtmspe, trim = 0.1)

# perform cross-validation for an MM regression model
fitLmrob <- lmrob(Y ~ ., data = coleman, maxit.scale = 500)
cvLmrob <- perry(fitLmrob, splits = folds,
                 cost = rtmspe, trim = 0.1)

# perform cross-validation for an LTS regression model
fitLts <- ltsReg(Y ~ ., data = coleman)
cvLts <- perry(fitLts, splits = folds,
               cost = rtmspe, trim = 0.1)

# combine results into one object
cv <- perrySelect(LS = cvLm, MM = cvLmrob, LTS = cvLts,
                  .selectBest = "min")
cv

## convert MM regression results to data frame for plotting
# all replications for box plot
cvLmrobBox <- setupPerryPlot(cvLmrob, which = "box")
perryPlot(cvLmrobBox)
# aggregated results for dot plot
cvLmrobDot <- setupPerryPlot(cvLmrob, which = "dot", seFactor = 2)
perryPlot(cvLmrobDot)

## convert combined results to data frame for plotting
# all replications for box plot
cvBox <- setupPerryPlot(cv, which = "box")
perryPlot(cvBox)
# aggregated results for dot plot
cvDot <- setupPerryPlot(cv, which = "dot", seFactor = 2)
perryPlot(cvDot)
# }

Run the code above in your browser using DataLab