R: Combine 'mids' objects by columns

cbind.mids {mice} | R Documentation

## Combine `mids` objects by columns

### Description

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.

### Usage

    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.

### 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.

### Value

An S3 object of class `mids`

### Note

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

`data` | Columnwise combination of the data in `x` and `y`
`imp` | Combines the imputed values from `x` and `y`
`m` | Taken from `x$m`
`where` | Columnwise combination of `x$where` and `y$where`
`blocks` | Combines `x$blocks` and `y$blocks`
`call` | Vector, `call[1]` creates `x`, `call[2]` is call to `cbind.mids`
`nmis` | Equals `c(x$nmis, y$nmis)`
`method` | Combines `x$method` and `y$method`
`predictorMatrix` | Combination with zeroes on the off-diagonal blocks
`visitSequence` | Combined as `c(x$visitSequence, y$visitSequence)`
`formulas` | Combined as `c(x$formulas, y$formulas)`
`post` | Combined as `c(x$post, y$post)`
`blots` | Combined as `c(x$blots, y$blots)`
`ignore` | Taken from `x$ignore`
`seed` | Taken from `x$seed`
`iteration` | Taken from `x$iteration`
`lastSeedValue` | Taken from `x$lastSeedValue`
`chainMean` | Combined from `x$chainMean` and `y$chainMean`
`chainVar` | Combined from `x$chainVar` and `y$chainVar`
`loggedEvents` | Taken from `x$loggedEvents`
`version` | Current package version
`date` | Current date

### Author(s)

Karin Groothuis-Oudshoorn, Stef van Buuren

### See Also

`cbind`, `rbind.mids`, `ibind`, `mids`

### Examples

    # impute four variables at once (default)
    imp <- mice(nhanes, m = 1, maxit = 1, print = FALSE)
    imp$predictorMatrix

    # 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

    # Append the other way around
    imp21 <- cbind(imp2, imp1)
    imp21$predictorMatrix

    # 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))

    # Combine mids object with data frame
    imp5 <- cbind(imp3, nhanes2)
    head(complete(imp5))

[Package mice version 3.14.0 Index]