mice.impute.grouped: Imputation of a Variable with Grouped Values

Description Usage Arguments Value See Also Examples

View source: R/mice.impute.grouped.R

Description

Imputes a variable with continuous values whose original values are only available as grouped values.

Usage

1
mice.impute.grouped(y, ry, x, low=NULL, upp=NULL,  ...)

Arguments

y

Incomplete data vector of length n

ry

Vector of missing data pattern (FALSE – missing, TRUE – observed)

x

Matrix (n x p) of complete covariates.

low

Vector with lower bound of grouping interval

upp

Vector with upper bound of grouping interval

...

Further arguments to be passed

Value

A vector of length nmis=sum(!ry) with imputed values.

See Also

This function uses the grouped::grouped function in the grouped package.

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
36
## Not run: 
#############################################################################
# EXAMPLE 1: Imputation of grouped data
#############################################################################

data(data.ma06)
data <- data.ma06

# define the variable "FC_imp" which should contain the variables to be imputed
data$FC_imp <- NA
V <- ncol(data)
# variables not to be used for imputation
vars_elim <-  c("id", "FC","FC_low","FC_upp")

# define imputation methods
impM <- rep("norm", V)
names(impM) <- colnames(data)
impM[  vars_elim ] <- ""
impM[ "FC_imp" ] <- "grouped"

# define predictor matrix
predM <- 1 - diag( 0, V)
rownames(predM) <- colnames(predM) <- colnames(data)
predM[vars_elim, ] <- 0
predM[,vars_elim] <- 0

# define lower and upper boundaries of the grouping intervals
low <- list("FC_imp"=data$FC_low )
upp <- list("FC_imp"=data$FC_upp )

# perform imputation
imp <- mice::mice( data, method=impM, predictorMatrix=predM,
        m=1, maxit=3, allow.na=TRUE,  low=low, upp=upp)
head( mice::complete(imp))

## End(Not run)

miceadds documentation built on Oct. 19, 2018, 5:05 p.m.