This helper function attempts to find blocks of variables in the
specification of the formulas and/or predictorMatrix
objects. Blocks specified by formulas may consist of
multiple variables. Blocks specified by predictorMatrix are
assumed to consist of single variables. Any duplicates in names are
removed, and the formula specification is preferred.
predictorMatrix and formulas. When both arguments
specify models for the same block, the model for the
predictMatrix is removed, and priority is given to the
specification given in formulas.
Arguments
- formulas
A named list of formula's, or expressions that can be converted into formula's by
as.formula. List elements correspond to blocks. The block to which the list element applies is identified by its name, so list names must correspond to block names. Theformulasargument is an alternative to thepredictorMatrixargument that allows for more flexibility in specifying imputation models, e.g., for specifying interaction terms.- predictorMatrix
A numeric matrix of
length(blocks)rows andncol(data)columns, containing 0/1 data specifying the set of predictors to be used for each target column. Each row corresponds to a variable block, i.e., a set of variables to be imputed. A value of1means that the column variable is used as a predictor for the target block (in the rows). By default, thepredictorMatrixis a square matrix ofncol(data)rows and columns with all 1's, except for the diagonal. Note: For two-level imputation models (which have"2l"in their names) other codes (e.g,2or-2) are also allowed. The cluster variable (code-2) can be integer, numeric or factor, but not character. See the article "Codes in the predictor matrix". APOSIXctorPOSIXltpredictor enters the imputation model as its number of seconds, centered at its mean, also in a formula (e.g.I(time^2)is the square of the centered value). Block methods such asjomoImputeget the data as they are.
Examples
form <- list(bmi + hyp ~ chl + age, chl ~ bmi)
pred <- make.predictorMatrix(nhanes[, c("age", "chl")])
construct.blocks(formulas = form, pred = pred)
#> $F1
#> [1] "bmi" "hyp"
#>
#> $chl
#> [1] "chl"
#>
#> $age
#> [1] "age"
#>
