make.formulas: Creates a 'formulas' argument

Description Usage Arguments Value See Also Examples

View source: R/formula.R

Description

This helper function creates a valid formulas object. The formulas object is an argument to the mice function. It is a list of formula's that specifies the target variables and the predictors by means of the standard ~ operator.

Usage

1
make.formulas(data, blocks = make.blocks(data), predictorMatrix = NULL)

Arguments

data

A data.frame with the source data

blocks

An optional specification for blocks of variables in the rows. The default assigns each variable in its own block.

predictorMatrix

A predictorMatrix specified by the user.

Value

A list of formula's.

See Also

make.blocks, make.predictorMatrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
f1 <- make.formulas(nhanes)
f1
f2 <- make.formulas(nhanes, blocks = make.blocks(nhanes, "collect"))
f2

# for editing, it may be easier to work with the character vector
c1 <- as.character(f1)
c1

# fold it back into a formula list
f3 <- name.formulas(lapply(c1, as.formula))
f3

Example output

Loading required package: lattice

Attaching package: 'mice'

The following objects are masked from 'package:base':

    cbind, rbind

$age
age ~ 0 + bmi + hyp + chl
<environment: 0x76b6618>

$bmi
bmi ~ 0 + age + hyp + chl
<environment: 0x76b6618>

$hyp
hyp ~ 0 + age + bmi + chl
<environment: 0x76b6618>

$chl
chl ~ 0 + age + bmi + hyp
<environment: 0x76b6618>

$collect
age + bmi + hyp + chl ~ 0
<environment: 0x801d630>

[1] "age ~ 0 + bmi + hyp + chl" "bmi ~ 0 + age + hyp + chl"
[3] "hyp ~ 0 + age + bmi + chl" "chl ~ 0 + age + bmi + hyp"
$age
age ~ 0 + bmi + hyp + chl
<environment: 0x8027440>

$bmi
bmi ~ 0 + age + hyp + chl
<environment: 0x8027440>

$hyp
hyp ~ 0 + age + bmi + chl
<environment: 0x8027440>

$chl
chl ~ 0 + age + bmi + hyp
<environment: 0x8027440>

mice documentation built on Jan. 27, 2021, 5:10 p.m.

Related to make.formulas in mice...