Learn R Programming

mice (version 2.30)

cbind.mids: Columnwise combination of a mids object.

Description

This function combines two mids objects columnwise into a single object of class mids, or combines a mids object with a vector, matrix, factor or data.frame columnwise into an object of class mids. The number of rows in the (incomplete) data x$data and y (or y$data if y is a mids object) should be equal. If y is a mids object then the number of imputations in x and y should be equal. Note: If y is a vector or factor its original name is lost and it will be denoted with y in the mids object.

Usage

cbind.mids(x, y, ...)

Arguments

x

A mids object.

y

A mids object or a data.frame, matrix, factor or vector.

Additional data.frame, matrix, vector or factor. These can be given as named arguments.

Value

An S3 object of class mids

See Also

rbind.mids, ibind, mids

Examples

Run this code
# NOT RUN {
# append 'forgotten' variable bmi to imp
temp <- boys[,c(1:3,5:9)]
imp  <- mice(temp,maxit=1,m=2)
imp2 <- cbind.mids(imp, data.frame(bmi=boys$bmi))

# append maturation score to imp (numerical)
mat  <- (as.integer(temp$gen) + as.integer(temp$phb)
+ as.integer(cut(temp$tv,breaks=c(0,3,6,10,15,20,25))))
imp2 <- cbind.mids(imp, as.data.frame(mat))

# append maturation score to imp (factor)
# known issue: new column name is 'y', not 'mat'
mat  <- as.factor(mat)
imp2 <- cbind.mids(imp, mat)

# append data frame with two columns to imp
temp2 <- data.frame(bmi=boys$bmi,mat=as.factor(mat))
imp2  <- cbind.mids(imp, temp2)

# combine two mids objects
impa <- mice(temp, maxit=1, m=2)
impb <- mice(temp2, maxit=2, m=2)

# first a then b
impab <- cbind.mids(impa, impb)

# first b then a
impba <- cbind.mids(impb, impa)

# }

Run the code above in your browser using DataLab