aggregate-methods: Method for aggregating simulation results

Description Usage Arguments Value Details Methods Author(s) References See Also Examples

Description

Aggregate simulation results, i.e, split the data into subsets if applicable and compute summary statistics.

Usage

1
2
## S4 method for signature 'SimResults'
aggregate(x, select = NULL, FUN = mean, ...)

Arguments

x

the simulation results to be aggregated, i.e., an object of class "SimResults".

select

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

FUN

a function to compute the summary statistics (defaults to mean).

...

additional arguments to be passed down to methods.

Value

A data frame containing the summary statistics for the different subsets of the simulation results.

Details

The summary statistics of the simulation results are computed using the aggregate method for the data frame in slot values.

Methods

signature(x = "SimResults")

aggregate 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

aggregate, "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
#### 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 = 0.02, 
    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)

## aggregate
aggregate(results)            # means of results
aggregate(results, FUN = sd)  # standard deviations of results


#### 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 = 0.02, 
    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)

## aggregate
aggregate(results)            # means of results
aggregate(results, FUN = sd)  # standard deviations of results

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