WideToLong: WideToLong: Converting from wide to long formats

Description Usage Arguments References See Also Examples

View source: R/helper_functions.R View source: R/mice_extentions.R

Description

In longitudinal or other multiple response studies, data presented in a long format will often feature dependence between rows. While this is the preferred format for lme4, such a format would hide important information from multiple imputation models and make the MAR assumption less plausible. Hense, the suggestion is to impute data in a wide format, where rows are again independent, and then return the mids object to a long format for use with FitModel, ForwardSelect, or BackwardEliminate.

Usage

1
WideToLong(data, id.name, response.base, time.varying.bases = c(""), sep = ".")

Arguments

data

A data frame or mids object in "wide" format. Specifically, both the response and any time varying covariates should be specified as multiple columns with the same base name, but a different suffix. The suffix values will be the future period labels.

id.name

The name of the identifying variable, a character string.

response

The common prefix for the response variable, a character string.

time.varying.bases

A character vector of name prefixes for time-varying covariates.

sep

The character delimiter separating the variable name base from the period identifier.

References

Stef van Buuren, Karin Groothuis-Oudshoorn (2011). mice: Multivariate Imputation by Chained Equations in R. Journal of Statistical Software, 45(3), 1-67. URL http://www.jstatsoft.org/v45/i03/.

See Also

LongToWide

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
wide.df <- data.frame(pid           = 1:100,
                      my.response.1 = rnorm(100),
                      my.response.2 = rnorm(100),
                      x.1           = rnorm(100),
                      x.2           = rnorm(100))
# add missingness

wide.df[25:50, "my.response.2"] <- NA
wide.df[45:55, "x.1"] <- NA

wide.mids <- ImputeData(wide.df, droplist = c("pid"))
long.mids <- WideToLong(wide.mids, "pid", "my.response", c("x"), sep = ".")

my.model <- FitModel(my.response ~ (1 | pid) + x, data = long.mids)
summary(my.model)

google/glmmplus documentation built on May 17, 2019, 7:47 a.m.