Description Usage Arguments Value Details Methods Author(s) References See Also Examples
Aggregate simulation results, i.e, split the data into subsets if applicable and compute summary statistics.
1 2 |
x |
the simulation results to be aggregated, i.e., an object of class
|
select |
a character vector specifying the columns to be aggregated. It
must be a subset of the |
FUN |
a scalar function to compute the summary statistics (defaults to
|
... |
additional arguments to be passed down to
|
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.
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
.
x = "SimResults"
aggregate simulation results.
Andreas Alfons
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. doi: 10.18637/jss.v037.i03.
aggregate
, apply
,
"SimResults"
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 | #### design-based simulation
set.seed(12345) # for reproducibility
data(eusilcP) # load data
## control objects for sampling and contamination
sc <- SampleControl(size = 500, k = 50)
cc <- DARContControl(target = "eqIncome", epsilon = 0.02,
fun = function(x) x * 25)
## function for simulation runs
sim <- function(x) {
c(mean = mean(x$eqIncome), trimmed = mean(x$eqIncome, 0.02))
}
## run simulation
results <- runSimulation(eusilcP,
sc, contControl = cc, fun = sim)
## aggregate
aggregate(results) # means of results
aggregate(results, FUN = sd) # standard deviations of results
#### model-based simulation
set.seed(12345) # for reproducibility
## 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 = 500, distribution = rgnorm,
dots = list(means = means))
cc <- DCARContControl(target = "value",
epsilon = 0.02, dots = list(mean = 15))
## function for simulation runs
sim <- function(x) {
c(mean = mean(x$value),
trimmed = mean(x$value, trim = 0.02),
median = median(x$value))
}
## run simulation
results <- runSimulation(dc, nrep = 50,
contControl = cc, design = "group", fun = sim)
## aggregate
aggregate(results) # means of results
aggregate(results, FUN = sd) # standard deviations of results
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.