runSimulation(simFrame)
runSimulation()所属R语言包:simFrame
Run a simulation experiment
运行一个模拟实验
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Generic function for running a simulation experiment.
运行模拟实验的通用功能。
用法----------Usage----------
runSimulation(x, setup, nrep, control, contControl = NULL,
NAControl = NULL, design = character(), fun, ...,
SAE = FALSE)
runSim(...)
参数----------Arguments----------
参数:x
a data.frame (for design-based simulation or simulation based on real data) or a control object for data generation inheriting from "VirtualDataControl" (for model-based simulation or mixed simulation designs).
一个data.frame设计为基础的模拟或模拟真实数据的基础上,或继承自"VirtualDataControl"(基于模型的模拟或混合仿真设计)的数据生成一个控制对象。
参数:setup
an object of class "SampleSetup", containing previously set up samples, or a control class for setting up samples inheriting from "VirtualSampleControl".
类的一个对象"SampleSetup",包含以前成立的样品,或一个控件类继承自"VirtualSampleControl"样品。
参数:nrep
a non-negative integer giving the number of repetitions of the simulation experiment (for model-based simulation, mixed simulation designs or simulation based on real data).
一个非负的整数,给出的模拟实验的重复数(基于模型的模拟,混合模拟根据实际的数据的设计或模拟)。
参数:control
a control object of class "SimControl"
控制对象的类"SimControl"
参数:contControl
an object of a class inheriting from "VirtualContControl", controlling contamination in the simulation experiment.
一个类继承自"VirtualContControl",控制污染的模拟实验对象。
参数:NAControl
an object of a class inheriting from "VirtualNAControl", controlling the insertion of missing values in the simulation experiment.
一个对象的一个类继承自"VirtualNAControl",控制插入缺失值的模拟实验。
参数:design
a character vector specifying variables (columns) to be used for splitting the data into domains. The simulations, including contamination and the insertion of missing values (unless SAE=TRUE), are then performed on every domain.
分裂域数据转换成用于一个字符矢量指定变量(列)。模拟,包括污染和插入缺失值(除非SAE=TRUE),然后在每个域。
参数:fun
a function to be applied in each simulation run.
一个函数被应用于在每个模拟运行。
参数:...
for runSimulation, additional arguments to be passed to fun. For runSim, arguments to be passed to runSimulation.
runSimulation,其他参数传递给fun。对于runSim,参数被传递到runSimulation。
参数:SAE
a logical indicating whether small area estimation will be used in the simulation experiment.
一个逻辑指示是否将被用于在模拟实验中的小区域估计。
Details
详细信息----------Details----------
For convenience, the slots of control may be supplied as arguments.
为方便起见,时隙control可以作为参数提供。
There are some requirements for slot fun of the control object control. The function must return a numeric vector, or a list with the two components values (a numeric vector) and add (additional results of any class, e.g., statistical models). Note that the latter is computationally slightly more expensive. A data.frame is passed to fun in every simulation run. The corresponding argument must be called x. If comparisons with the original data need to be made, e.g., for evaluating the quality of imputation methods, the function should have an argument called orig. If different domains are used in the simulation, the indices of the current domain can be passed to the function via an argument called domain.
有一些要求插槽fun的控制对象control。该函数必须返回一个数值向量或列表的两个组成部分values(数字向量)和add(附加任何类,例如,统计模型)。请注意,后者是计算稍微更昂贵。 Adata.frame传递给fun在每次模拟运行。对应参数必须叫做x。例如,如果需要与原始数据进行比较,评估质量的估算方法,函数应该有一个参数叫做orig。如果模拟中使用的不同的域,在当前域的指标,可以通过功能通过参数称为domain。
For small area estimation, the following points have to be kept in mind. The design for splitting the data must be supplied and SAE must be set to TRUE. However, the data are not actually split into the specified domains. Instead, the whole data set (sample) is passed to fun. Also contamination and missing values are added to the whole data (sample). Last, but not least, the function must have a domain argument so that the current domain can be extracted from the whole data (sample).
对于小面积的估计,必须牢记以下几点。的design分裂的数据必须提供和SAE设置为TRUE。然而,该数据实际上不是分成指定的域。相反,整个数据集(样本)被传递给fun。污染和遗漏值将被添加到整个数据(样本)。最后,但并非最不重要的一点是,该函数必须有一个domain参数,以便可以提取当前域的整个数据(样本)。
In every simulation run, fun is evaluated using try. Hence no results are lost if computations fail in any of the simulation runs.
在每一个仿真的运行,fun被评为使用try。因此,没有结果都将丢失,如果计算在任何的模拟运行失败。
runSim is a wrapper for runSimulation.
runSim的包装runSimulation。
值----------Value----------
An object of class "SimResults".
对象的类"SimResults"。
方法----------Methods----------
convenience wrapper that allows the slots of control to be supplied
方便的包装,允许提供的插槽control
control = "SimControl"</dt> run a simulation experiment based on real data
控制=“SimControl”的</> </ DT>运行一个基于真实数据的仿真实验
control = "SimControl"</dt> run a simulation experiment based on real data
控制=“SimControl”的</> </ DT>运行一个基于真实数据的仿真实验
control = "SimControl"</dt> run a design-based simulation experiment with
控制=“SimControl”的</> </ DT>运行一个基于设计的模拟实验
nrep = "missing", control = "SimControl"</dt> run a design-based simulation
NREP =“失踪”,控制“SimControl”</ P> </ DT>运行设计为基础的模拟
control = "SimControl"</dt> run a model-based simulation experiment without
控制=“SimControl”的</> </ DT>运行基于模型的仿真实验,而
control = "SimControl"</dt> run a model-based simulation experiment with
控制=“SimControl”的</> </ DT>运行基于模型的仿真实验,
nrep = "missing", control = "SimControl"</dt> run a simulation experiment using a mixed simulation design without repetitions (probably useless, but
NREP =“失踪”,控制“SimControl”</ P> </ DT>运行了仿真实验使用混合仿真设计,没有重复(可能是无用的,但
nrep = "numeric", control = "SimControl"</dt> run a simulation experiment
NREP =“数字”,控制“SimControl”</ P> </ DT>运行模拟实验
(作者)----------Author(s)----------
Andreas Alfons
参考文献----------References----------
Statistical Simulation: The R Package <code>simFrame</code>. Journal of Statistical Software, 37(3), 1–36. URL http://www.jstatsoft.org/v37/i03/.
参见----------See Also----------
"SimControl", "SimResults", simBwplot, simDensityplot, simXyplot
"SimControl","SimResults",simBwplot,simDensityplot,simXyplot
实例----------Examples----------
#### 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 and explore results[#运行仿真和探索的结果]
results <- runSimulation(eusilcP,
sc, contControl = cc, fun = sim)
head(results)
aggregate(results)
tv <- mean(eusilcP$eqIncome) # true population mean[真正的人口是什么意思]
plot(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 and explore results[#运行仿真和探索的结果]
results <- runSimulation(dc, nrep = 50,
contControl = cc, design = "group", fun = sim)
head(results)
aggregate(results)
plot(results, true = means)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|