Last chance! 50% off unlimited learning
Sale ends in
Generic function for producing kernel density plots.
simDensityplot(x, …)# S4 method for SimResults
simDensityplot(x, true = NULL, epsilon, NArate, select, …)
the object to be plotted. For plotting simulation results, this
must be an object of class "SimResults"
.
a numeric vector giving the true values. If supplied, reference lines are drawn in the corresponding panels.
a numeric vector specifying contamination levels. If supplied, the values corresponding to these contamination levels are extracted from the simulation results and plotted.
a numeric vector specifying missing value rates. If supplied, the values corresponding to these missing value rates are extracted from the simulation results and plotted.
a character vector specifying the columns to be plotted. It
must be a subset of the colnames
slot of x
, which is the
default.
additional arguments to be passed down to methods and eventually
to densityplot
.
An object of class "trellis"
. The
update
method can be used to update
components of the object and the print
method (usually called by default) will plot it on an appropriate plotting
device.
x = "SimResults"
produce kernel density plots of simulation results.
For simulation results with multiple contamination levels or missing value rates, conditional kernel density plots are produced.
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. 10.18637/jss.v037.i03.
simBwplot
, simXyplot
,
densityplot
,
"'>SimResults"
# NOT RUN {
#### 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)
## plot results
tv <- mean(eusilcP$eqIncome) # true population mean
simDensityplot(results, true = tv)
#### 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)
## plot results
simDensityplot(results, true = means)
# }
Run the code above in your browser using DataLab