Learn R Programming

miceadds (version 2.2-0)

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

Description

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

Usage

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

Run this code
## 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 , imputationMethod = impM , predictorMatrix = predM , 
# 	    m=1 , maxit=3 , allow.na=TRUE ,  low=low , upp=upp)
# head( mice::complete(imp))
# ## End(Not run)

Run the code above in your browser using DataLab