Learn R Programming

simsalapar (version 1.0-12)

varlist: Variable Specification List - Generation and Class

Description

Generate variable specification lists. These are objects of the formal (aka “S4”) class "varlist". This class simply extends "namedList" and has a validity method (see validObject).

Usage

varlist(...)
dimnames2varlist(dmn)


# S4 method for varlist
show(object)

Value

an object of formal (aka “S4”) class "varlist".

Arguments

...

of the form

nam1 = list(....),

nam2 = list(....),

........

namk = list(....)

i.e, a “list” of variable specifications using “sub lists” list(....) = list(value = <vv>, type = <tp>, expr = <e>), see the details and the examples below.

dmn

named dimnames, a list.

object

a "varlist" object.

Author

Martin Maechler.

Details

value is typically an atomic vector (is.atomic) or a list, e.g., of functions; in the latter case, typically with names.

type can be one of "N", "frozen", "grid", or "inner". In short:

"N"

This type is reserved for a (single) variable named n.sim which provides the simulation replications; if it is not given, n.sim is implicitly treated as 1.

"frozen"

Variables of this type remain fixed (they do not vary) throughout the whole simultion study. They affect the final result but do not appear as a dimension in the result array of the simulation study. This is the default type (apart from n.sim which defaults to "N").

"grid"

Variables of this type are used to build a (physical) grid (a data.frame) with number of rows equal to the product of the lengths of all variables of this type. The simulation will use this grid to iterate n.sim times over all of its rows for conducting the required computations. Conceptually, this corresponds to iterating over a virtual grid seen as n.sim copies of the (physical) grid pasted together. The computations for one row in this virtual grid form one sub-job. One can use one of doLapply(), doForeach(), doRmpi(), doMclapply(), or doClusterApply() to iterate over all sub-jobs.

"inner"

Variables of this type are all dealt with within a sub-job for reasons of convenience, speed, load balancing etc.

The dimnames2varlist() functions creates a varlist from a named list of character vectors, typically resulting from dimnames(tt) of a table tt, see the Titanic example below.

For more details, see Hofert and Mächler (2014), and also the examples in demo(package="simsalapar") .

See Also

namedList; getEl for easy extraction of elements from a "varlist".

The toLatex method for varlists, toLatex.varlist.

doLapply(), doForeach(), doRmpi(), doMclapply(), doClusterApply() for the functions to iterate over the virtual grid.

Examples

Run this code
showClass("varlist")

vList <- varlist(
    n.sim = list(value = 1000, expr = quote(N[sim])), # type = N
    n     = list(type="grid", value = c(20, 100, 500)), # sample sizes
    meth  = list(type="grid", expr = quote(italic(method)),
                 value = c("classical", "robust")),
    alpha = list(value = 0.95)) # default type = "frozen"

str(vList)# note the default 'expr' for  n and alpha; and type of alpha

## For more extensive examples, see also
demo(package="simsalapar")

## coerce to simple list  .. and back :
lvl <- as(vList, "list")
stopifnot(identical(
    do.call(varlist, lvl),
    vList ))

## From a data.frame to a LaTeX table :
str(dimnames(Titanic))
vlTitan <- dimnames2varlist(dimnames(Titanic))
vlTitan  # default 'type = "grid"' here
toLatex(vlTitan)

Run the code above in your browser using DataLab