visitSequence.determine: Automatic Determination of a Visit Sequence in 'mice'

Description Usage Arguments Value Author(s) See Also Examples

View source: R/visitSequence.determine.R

Description

This function automatically determines a visit sequence for a specified model in mice::mice when passive variables are defined as imputation methods. Note that redundant visits could be computed and a user should check the plausibility of the result.

Usage

1
visitSequence.determine(impMethod, vis, data, maxit = 10)

Arguments

impMethod

Vector with imputation methods

vis

Initial vector of visit sequence

data

Data frame to be used for multiple imputations

maxit

Maximum number of iteration for computation of the updated visit sequence

Value

Updated vector of the visit sequence

Author(s)

Alexander Robitzsch

See Also

mice::mice

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#############################################################################
# EXAMPLE 1: Visit sequence for a small imputation model
#############################################################################

data( data.smallscale )
# select a small number of variables
dat <- data.smallscale[ , paste0("v",1:4) ]
V <- ncol(dat)

# define initial vector of imputation methods
impMethod <- rep("norm" , V)
names(impMethod) <- colnames(dat) 
# define variable names and imputation method for passive variables in a data frame
dfr.impMeth <- data.frame( "variable" = NA , 
                  "impMethod" =  NA )
dfr.impMeth[1,] <- c("v1_v1" , "~ I(v1^2)" )
dfr.impMeth[2,] <- c("v2_v4" , "~ I(v2*v4)" )
dfr.impMeth[3,] <- c("v4log" , "~ I( log(abs(v4)))" )
dfr.impMeth[4,] <- c("v12" , "~ I( v1 + v2 + 3*v1_v1 - v2_v4 )" )
# add variables to dataset and imputation methods
VV <- nrow(dfr.impMeth)
for (vv in 1:VV){
    impMethod[ dfr.impMeth[vv,1] ] <- dfr.impMeth[vv,2]
    dat[ , dfr.impMeth[vv,1] ] <- NA
                }

# run empty imputation model to obtain initial vector of visit sequence
imp0 <- mice::mice( dat , m=1 , imputationMethod = impMethod , maxit=0 )
imp0$vis

# update visit sequence
vis1 <- miceadds::visitSequence.determine( impMethod=impMethod , vis=imp0$vis , data = dat)

# imputation with updated visit sequence
imp <- mice::mice( dat, m=1, imputationMethod=impMethod, visitSequence=vis1, maxit=2)

miceadds documentation built on Aug. 25, 2017, 1:03 a.m.