Learn R Programming

simFrame (version 0.1.2)

aggregate-methods: Method for aggregating simulation results

Description

Aggregate simulation results.

Usage

## S3 method for class 'SimResults':
aggregate(x, select = NULL, FUN = mean, \dots)

Arguments

x
the simulation results to be aggregated, i.e., an object of class "SimResults".
select
a character vector specifying the columns to be aggregated. It must be a subset of the colnames slot of x, which is the default.
FUN
a scalar function to compute the summary statistics (defaults to mean).
...
additional arguments to be passed down to aggregate or apply.

Details

If contamination or missing values have been inserted or the simulations have been split into different domains, aggregate is called to compute the summary statistics for the respective subsets. Otherwise, apply is called to compute the summary statistics for each column specified by select.

Value

If contamination or missing values have been inserted or the simulations have been split into different domains, a data.frame is returned, otherwise a vector.

See Also

aggregate, apply

Examples

Run this code
## for reproducibility
set.seed(1234)

## function for generating data
grnorm <- 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.5)
dc <- DataControl(size = 500, distribution = grnorm, 
    dots = list(means = means))
cc <- DCARContControl(target = "value", 
    epsilon = 0.1, dots = list(mean = 10))

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

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

## aggregate
aggregate(results)

Run the code above in your browser using DataLab