simPlot: Plot simulation results

Description Usage Arguments Value Methods for function simPlot Methods for function autoplot Methods for function plot Author(s) References See Also Examples

Description

Plot simulation results. It is thereby possible to produce box plots, density plots, as well as to plot the average results against some tuning parameter. Although a suitable plot is selected automatically depending on the structure of the results, the default behavior can be overriden.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## S4 method for signature 'SimResults'
simPlot(object, data = NULL, cont = NULL, 
        miss = NULL, select = NULL, 
        method = c("box", "density", "line"), 
        average = c("mean", "median"), ...)

## S4 method for signature 'data.frame'
simPlot(object, mapping = attr(object, "mapping"), 
        facets = attr(object, "facets"), 
        labels = NULL, ...)

## S4 method for signature 'SimResults'
autoplot(object, ...)

## S4 method for signature 'SimResults,missing'
plot(x, y , ...)

Arguments

object, x

the simulation results to be plotted, i.e., an object of class "SimResults". For simPlot, this may also be a data frame constructed from such an object via fortify.

y

not used.

data

an optional integer or logical index vector specifying the data configurations for which to plot simulation results.

cont

an optional integer or logical index vector specifying the contamination settings for which to plot simulation results.

miss

an optional integer or logical index vector specifying the missing data settings for which to plot simulation results.

select

an optional integer, character or logical vector specifying the columns to be plotted. It must specify a subset of the colnames slot of the simulation results, which is the default.

method

a character string specifying which plot to produce. Possible values are "box" for a box plot, "density" for a density plot or "line" for plotting the average results against some tuning parameter. If not specified, a suitable plot is selected automatically.

average

if method is "line", a character string specifying how the averages should be computed. Possible values are "mean" for the mean (the default) or "median" for the median.

mapping

an aesthetic mapping to override the default behavior (see aes or aes_string).

facets

a faceting formula to override the default behavior. If supplied, facet_wrap or facet_grid is called depending on whether the formula is one-sided or two-sided.

labels

an optional character vector specifying specifying labels for the simulation results to be used in the plot instead of the column names.

...

additional arguments to be passed down, eventually to the function drawing the visual representation (see geom_boxplot, geom_density, geom_smooth or geom_line).

Value

An object of class "ggplot" (see ggplot).

Methods for function simPlot

signature(object = "SimResults")

plot simulation results.

signature(object = "data.frame")

plot simulation results that have been converted to a data frame via fortify.

Methods for function autoplot

signature(object = "SimResults")

plot simulation results.

Methods for function plot

signature(x = "SimResults", y = "missing")

plot simulation results.

Author(s)

Andreas Alfons

References

Alfons, A., Templ, M. and Filzmoser, P. (2010) An Object-Oriented Framework for Statistical Simulation: The R Package simFrame. Journal of Statistical Software, 37(3), 1–36. URL http://www.jstatsoft.org/v37/i03/.

See Also

fortify, "SimResults"

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#### design-based simulation
data("eusilcP")  # load data

## control objects for sampling and contamination
sc <- SampleControl(size = 100, k = 50, seed = 12345)
cc <- ContControl(target = "eqIncome", 
    epsilon = seq(0, 0.05, by = 0.01), 
    fun = function(x) x * 10, type = "CAR")

## function for simulation runs
sim <- function(x) {
    c(mean = mean(x$eqIncome), trimmed = mean(x$eqIncome, 0.05))
}

## run simulation
results <- runSimulation(eusilcP, sc, contControl = cc, 
    fun = sim, seed = 12345)

## plot results
tv <- mean(eusilcP$eqIncome)  # true population mean
# all results
plot(results) + geom_hline(yintercept=tv)
# subset
plot(results, cont = 3) + geom_hline(yintercept=tv)



#### model-based simulation

## function for generating data
rgnorm <- function(n, means) {
    group <- sample(1:2, n, replace=TRUE)
    data.frame(group=group, value=rnorm(n) + means[group])
}

## control objects for data generation and contamination
means <- c(0, 0.25)
dc <- DataControl(size = 100, fun = rgnorm, 
    dots = list(means = means))
cc <- ContControl(target = "value", 
    epsilon = seq(0, 0.05, by = 0.01), 
    dots = list(mean = 10), type = "CCAR")

## function for simulation runs
sim <- function(x) {
    c(mean = mean(x$value), 
        trimmed = mean(x$value, trim = 0.05), 
        median = median(x$value))
}

## run simulation
results <- runSimulation(dc, nrep = 50, contControl = cc, 
    design = "group", fun = sim, seed = 12345)

## plot results
tv <- data.frame(mean=means, group=1:2)
# all results
plot(results) + geom_hline(aes(yintercept=mean), data=tv)
# subset
plot(results, cont = 3) + geom_hline(aes(yintercept=mean), data=tv)

aalfons/simFrame documentation built on June 3, 2017, 10:52 a.m.