This function combines two mids objects columnwise into a single object of class mids, or combines a single mids object with a vector, matrix, factor or data.frame columnwise into a mids object.

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

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

Details

Pre-requisites: If y is a mids-object, the rows of x$data and y$data should match, as well as the number of imputations (m). Other y are transformed into a data.frame whose rows should match with x$data.

The function renames any duplicated variable or block names by appending ".1", ".2" to duplicated names.

Note

The function constructs the elements of the new mids object as follows:

dataColumnwise combination of the data in x and y
impCombines the imputed values from x and y
mTaken from x$m
whereColumnwise combination of x$where and y$where
blocksCombines x$blocks and y$blocks
callVector, call[1] creates x, call[2] is call to cbind.mids
nmisEquals c(x$nmis, y$nmis)
methodCombines x$method and y$method
predictorMatrixCombination with zeroes on the off-diagonal blocks
visitSequenceCombined as c(x$visitSequence, y$visitSequence)
formulasCombined as c(x$formulas, y$formulas)
postCombined as c(x$post, y$post)
blotsCombined as c(x$blots, y$blots)
ignoreTaken from x$ignore
seedTaken from x$seed
iterationTaken from x$iteration
lastSeedValueTaken from x$lastSeedValue
chainMeanCombined from x$chainMean and y$chainMean
chainVarCombined from x$chainVar and y$chainVar
loggedEventsTaken from x$loggedEvents
versionCurrent package version
dateCurrent date

See also

Author

Karin Groothuis-Oudshoorn, Stef van Buuren

Examples

# impute four variables at once (default) imp <- mice(nhanes, m = 1, maxit = 1, print = FALSE) imp$predictorMatrix
#> age bmi hyp chl #> age 0 1 1 1 #> bmi 1 0 1 1 #> hyp 1 1 0 1 #> chl 1 1 1 0
# impute two by two data1 <- nhanes[, c("age", "bmi")] data2 <- nhanes[, c("hyp", "chl")] imp1 <- mice(data1, m = 2, maxit = 1, print = FALSE) imp2 <- mice(data2, m = 2, maxit = 1, print = FALSE) # Append two solutions imp12 <- cbind(imp1, imp2) # This is a different imputation model imp12$predictorMatrix
#> age bmi hyp chl #> age 0 1 0 0 #> bmi 1 0 0 0 #> hyp 0 0 0 1 #> chl 0 0 1 0
# Append the other way around imp21 <- cbind(imp2, imp1) imp21$predictorMatrix
#> hyp chl age bmi #> hyp 0 1 0 0 #> chl 1 0 0 0 #> age 0 0 0 1 #> bmi 0 0 1 0
# Append 'forgotten' variable chl data3 <- nhanes[, 1:3] imp3 <- mice(data3, maxit = 1, m = 2, print = FALSE) imp4 <- cbind(imp3, chl = nhanes$chl) # Of course, chl was not imputed head(complete(imp4))
#> age bmi hyp chl #> 1 1 26.3 1 NA #> 2 2 22.7 1 187 #> 3 1 22.5 1 187 #> 4 3 21.7 1 NA #> 5 1 20.4 1 113 #> 6 3 22.7 1 184
# Combine mids object with data frame imp5 <- cbind(imp3, nhanes2) head(complete(imp5))
#> age bmi hyp age.1 bmi.1 hyp.1 chl #> 1 1 26.3 1 20-39 NA <NA> NA #> 2 2 22.7 1 40-59 22.7 no 187 #> 3 1 22.5 1 20-39 NA no 187 #> 4 3 21.7 1 60-99 NA <NA> NA #> 5 1 20.4 1 20-39 20.4 no 113 #> 6 3 22.7 1 60-99 NA <NA> 184