Imputation of a Variable with Grouped Values
Imputes a variable with continuous values whose original values are only available as grouped values.
mice.impute.grouped(y, ry, x, low=NULL, upp=NULL, ...)
y |
Incomplete data vector of length |
ry |
Vector of missing data pattern ( |
x |
Matrix ( |
low |
Vector with lower bound of grouping interval |
upp |
Vector with upper bound of grouping interval |
... |
Further arguments to be passed |
A vector of length nmis=sum(!ry)
with imputed values.
This function uses the grouped::grouped
function in the grouped package.
## 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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.