umx_wide2long: umx_wide2long

umx_wide2longR Documentation

umx_wide2long

Description

Makes wide data long using reshape Hopefully a more robust interface to reshape() For twin data, this calls umx_wide2longTwinData(data =data, sep = sep, verbose = verbose)

Usage

umx_wide2long(
  data = df,
  timevar = list(condition = c("control", "expt")),
  repeated = list(example = c("easyexample", "hardexample"), grade = c("grd1", "grd2")),
  covs = c("Age", "Sex"),
  idvar = "PID",
  sep = "_T",
  verbose = FALSE
)

Arguments

data

A data.frame to make long.

timevar

A list of the conditions individuals are in that generate repeated measures, list(condition = c("control", "expt"))

repeated

A list of varied inputs and their levels: i.e., list(exam = c("easy", "hard"), ...)

covs

A vector of variables that do not vary, e.g., c("Age", "Sex", "IQ").

idvar

The column containing the unique ID of the subjects "PID".

sep

For twin data - calls = umx_wide2longTwinData default "_T"

verbose

Whether to be verbose (FALSE)

Details

This is for processing data in which subjects (identified by a idvar column, have repeated measures on one or more outcomes. The goal is to make the data into long format, for passing to functions like lme4::lmer(). You must:

  1. Set timevar. This is a list of the conditions that you repeated. The name becomes a column in the long output. e.g., list(difficulty = c("easy", "hard"))

  2. Set repeated This is a list of the measured outcomes, e.g. list(DV = c("NASA1_frust", "NASA2_frust"), effort = c("NASA1_eff", "NASA2_eff"))

  3. Set covs This is vector of non-repeated non-varying IVs c("age", "sex", "IQ").

Table: The resulting output is like this:

idvar condition Age DV
001 "easy" 45 10
001 "hard" 45 75
002 "easy" 19 54
002 "hard" 19 74

Value

  • a long version of the df.

See Also

  • reshape()

Other Miscellaneous Utility Functions: install.OpenMx(), libs(), qm(), umx, umxLav2RAM(), umxModelNames(), umxRAM2Lav(), umxVersion(), umx_array_shift(), umx_find_object(), umx_lower.tri(), umx_msg(), umx_open_CRAN_page(), umx_pad(), umx_print()

Examples

## Not run: 
timevar  = list(difficulty = c("easy", "hard"))
repeated = list(
   frustration = c("NASA1_frustration", "NASA2_frustration"), 
   effort      = c("NASA1_effort", "NASA2_effort")
)
df.l = umx_long2wide(data, timevar, repeated, covs = c("Age"), idvar = "PID")

## End(Not run)

tbates/umx documentation built on April 13, 2025, 7:22 a.m.