TwoStageControl-class {simFrame} | R Documentation |
Class "TwoStageControl"
Description
Class for controlling the setup of samples using a two-stage procedure.
Usage
TwoStageControl(..., fun1 = srs, fun2 = srs, size1 = NULL,
size2 = NULL, prob1 = NULL, prob2 = NULL,
dots1 = list(), dots2 = list())
Arguments
... |
the slots for the new object (see below). |
fun1 |
the function to be used for sampling in the first stage (the
first list component of slot |
fun2 |
the function to be used for sampling in the second stage (the
second list component of slot |
size1 |
the number of PSUs to sample in the first stage (the first list
component of slot |
size2 |
the number of items to sample in the second stage (the second
list component of slot |
prob1 |
the probability weights for the first stage (the first list
component of slot |
prob2 |
the probability weights for the second stage (the second list
component of slot |
dots1 |
additional arguments to be passed to the function for sampling
in the first stage (the first list component of slot |
dots2 |
additional arguments to be passed to the function for sampling
in the second stage (the second list component of slot |
Objects from the Class
Objects can be created by calls of the form new("TwoStageControl", ...)
or via the constructor TwoStageControl
.
Slots
design
:Object of class
"BasicVector"
specifying variables (columns) to be used for stratified sampling in the first stage.grouping
:Object of class
"BasicVector"
specifying grouping variables (columns) to be used for sampling primary sampling units (PSUs) and secondary sampling units (SSUs), respectively.fun
:Object of class
"list"
; a list of length two containing the functions to be used for sampling in the first and second stage, respectively (defaults tosrs
for both stages). The functions should return a vector containing the indices of the sampled items.size
:Object of class
"list"
; a list of length two, where each component contains an optional non-negative integer giving the number of items to sample in the first and second stage, respectively. In case of stratified sampling in the first stage, a vector of non-negative integers, each giving the number of PSUs to sample from the corresponding stratum, may be supplied. For the second stage, a vector of non-negative integers giving the number of items to sample from each PSU may be used.prob
:Object of class
"list"
; a list of length two, where each component gives optional probability weights for the first and second stage, respectively. Each component may thereby be a numerical vector, or a character string or integer vector specifying a variable (column) that contains the probability weights.dots
:Object of class
"list"
; a list of length two, where each component is again a list containing additional arguments to be passed to the corresponding function for sampling infun
.k
:Object of class
"numeric"
; a single positive integer giving the number of samples to be set up.
Details
There are some restrictions on the argument names of the functions for
sampling in fun
. If the sampling method needs population data as
input, the corresponding argument should be called x
and should expect
a data.frame
. If it only needs the population size as input, the
argument should be called N
. Note that the function is not expected
to have both x
and N
as arguments, and that the latter is
typically much faster. Furthermore, if the function has arguments for sample
size and probability weights, they should be called size
and
prob
, respectively. Note that a function with prob
as its only
argument is perfectly valid (for probability proportional to size sampling).
Further arguments may be supplied as a list via the slot dots
.
Extends
Class "VirtualSampleControl"
, directly.
Class "OptSampleControl"
, by class "VirtualSampleControl", distance 2.
Accessor and mutator methods
In addition to the accessor and mutator methods for the slots inherited from
"VirtualSampleControl"
, the following are available:
getDesign
signature(x = "TwoStageControl")
: get slotdesign
.setDesign
signature(x = "TwoStageControl")
: set slotdesign
.getGrouping
signature(x = "TwoStageControl")
: get slotgrouping
.setGrouping
signature(x = "TwoStageControl")
: set slotgrouping
.getCollect
signature(x = "TwoStageControl")
: get slotcollect
.setCollect
signature(x = "TwoStageControl")
: set slotcollect
.getFun
signature(x = "TwoStageControl")
: get slotfun
.setFun
signature(x = "TwoStageControl")
: set slotfun
.getSize
signature(x = "TwoStageControl")
: get slotsize
.setSize
signature(x = "TwoStageControl")
: set slotsize
.getProb
signature(x = "TwoStageControl")
: get slotprob
.setProb
signature(x = "TwoStageControl")
: set slotprob
.getDots
signature(x = "TwoStageControl")
: get slotdots
.setDots
signature(x = "TwoStageControl")
: set slotdots
.
Methods
In addition to the methods inherited from
"VirtualSampleControl"
, the following are available:
clusterSetup
signature(cl = "ANY", x = "data.frame", control = "TwoStageControl")
: set up multiple samples on a cluster.setup
signature(x = "data.frame", control = "TwoStageControl")
: set up multiple samples.show
signature(object = "TwoStageControl")
: print the object on the R console.
UML class diagram
A slightly simplified UML class diagram of the framework can be found in
Figure 1 of the package vignette An Object-Oriented Framework for
Statistical Simulation: The R Package simFrame
. Use
vignette("simFrame-intro")
to view this vignette.
Author(s)
Andreas Alfons
See Also
"VirtualSampleControl"
,
"SampleControl"
, "SampleSetup"
,
setup
, draw
Examples
showClass("TwoStageControl")