fortify.perry: Convert resampling-based prediction error results into a data...

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Extract all necessary information for plotting from resampling-based prediction error results and store it in a data frame.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  ## S3 method for class 'perry'
 fortify(model, data, select = NULL,
    reps = model$splits$R > 1, seFactor = NA, ...)

  ## S3 method for class 'perrySelect'
 fortify(model, data,
    subset = NULL, select = NULL,
    reps = model$splits$R > 1, seFactor = model$seFactor,
    ...)

  ## S3 method for class 'perryTuning'
 fortify(model, data, ...)

Arguments

model

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

data

currently ignored.

subset

a character, integer or logical vector indicating the subset of models to be converted.

select

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

reps

a logical indicating whether to convert the results from all replications (TRUE) or the aggregated results (FALSE). The former is suitable for box plots or smooth density plots, while the latter is suitable for dot plots or line plots (see perryPlot).

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.

...

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

Value

A data frame containing the columns listed below, as well as additional information stored in the attribute "facets" (default faceting formula for the plots).

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 reps is FALSE).

Upper

the upper end points of the error bars (only returned if reps is FALSE).

Note

Duplicate indices in subset or select are removed such that all models and prediction error results are unique.

Author(s)

Andreas Alfons

See Also

fortify, perryPlot, perryFit, perrySelect, perryTuning

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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, k.max = 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)
cv

## convert MM regression results to data frame for plotting
# all replications for box plot
cvLmrobBox <- fortify(cvLmrob, reps = TRUE)
perryPlot(cvLmrobBox)
# aggregated results for dot plot
cvLmrobDot <- fortify(cvLmrob, reps = FALSE, seFactor = 1)
perryPlot(cvLmrobDot)

## convert combined results to data frame for plotting
# all replications for box plot
cvBox <- fortify(cv, reps = TRUE)
perryPlot(cvBox)
# aggregated results for dot plot
cvDot <- fortify(cv, reps = FALSE, seFactor = 1)
perryPlot(cvDot)

aalfons/perry documentation built on May 10, 2019, 2:06 a.m.