This helper function generates a list of the type needed for
blocks
argument in the [=mice]{mice}
function.
Usage
make.blocks(
data,
partition = c("scatter", "collect", "void"),
calltype = "pred"
)
Arguments
- data
A
data.frame
, character vector with variable names, orlist
with variable names.- partition
A character vector of length 1 used to assign variables to blocks when
data
is adata.frame
. Value"scatter"
(default) will assign each column to it own block. Value"collect"
assigns all variables to one block, whereas"void"
produces an empty list.- calltype
A character vector of
length(block)
elements that indicates how the imputation model is specified. Ifcalltype = "pred"
(the default), the underlying imputation model is called by means of thetype
argument. Thetype
argument for blockh
is equivalent to rowh
in thepredictorMatrix
. The alternative iscalltype = "formula"
. This will passformulas[[h]]
to the underlying imputation function for blockh
, together with the current data. Thecalltype
of a block is set automatically during initialization. Where a choice is possible, calltype"formula"
is preferred over"pred"
since this is more flexible and extendable. However, what precisely happens depends also on the capabilities of the imputation function that is called.
Details
Choices "scatter"
and "collect"
represent to two
extreme scenarios for assigning variables to imputation blocks.
Use "scatter"
to create an imputation model based on
fully conditionally specification (FCS). Use "collect"
to
gather all variables to be imputed by a joint model (JM).
Scenario's in-between these two extremes represent
hybrid imputation models that combine FCS and JM.
Any variable not listed in will not be imputed.
Specification "void"
represents the extreme scenario that
skips imputation of all variables.
A variable may be a member of multiple blocks. The variable will be re-imputed in each block, so the final imputations for variable will come from the last block that was executed. This scenario may be useful where the same complete background factors appear in multiple imputation blocks.
A variable may appear multiple times within a given block. If a univariate imputation model is applied to such a block, then the variable is re-imputed each time as it appears in the block.
Examples
make.blocks(nhanes)
#> $age
#> [1] "age"
#>
#> $bmi
#> [1] "bmi"
#>
#> $hyp
#> [1] "hyp"
#>
#> $chl
#> [1] "chl"
#>
#> attr(,"calltype")
#> age bmi hyp chl
#> "pred" "pred" "pred" "pred"
make.blocks(c("age", "sex", "edu"))
#> $age
#> [1] "age"
#>
#> $sex
#> [1] "sex"
#>
#> $edu
#> [1] "edu"
#>
#> attr(,"calltype")
#> age sex edu
#> "pred" "pred" "pred"