Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

umxFactor

umxFactor


Description

A convenient version of mxFactor() supporting the common case in which the factor levels are those in the variable.

Usage

umxFactor(
  x = character(),
  levels = NULL,
  labels = levels,
  exclude = NA,
  ordered = TRUE,
  collapse = FALSE,
  verbose = FALSE,
  sep = NA
)

Arguments

x

A variable to recode as an mxFactor (see mxFactor())

levels

(default NULL). Like factor() but UNLIKE mxFactor(), unique values will be used if levels not specified.

labels

= levels (see mxFactor())

exclude

= NA (see mxFactor())

ordered

= TRUE By default return an ordered mxFactor

collapse

= FALSE (see mxFactor())

verbose

Whether to tell user about such things as coercing to factor

sep

If twin data are being used, the string that separates the base from twin index will try and ensure factor levels same across all twins.

Value

References

See Also

Examples

umxFactor(letters)
umxFactor(letters, verbose = TRUE) # report coercions
umxFactor(letters, ordered = FALSE) # non-ordered factor like factor(x)
# Dataframe example:
x = umx_factor(mtcars[,c("cyl", "am")], ordered = FALSE); str(x)
# =================
# = Twin example: =
# =================
data(twinData)
tmp = twinData[, c("bmi1", "bmi2")]
tmp$bmi1[tmp$bmi1 <= 22] = 22
tmp$bmi2[tmp$bmi2 <= 22] = 22
# remember to factor _before_ breaking into MZ and DZ groups
x = umxFactor(tmp, sep = ""); str(x)
xmu_check_levels_identical(x, "bmi", sep="")

# Simple example to check behavior
x = round(10 * rnorm(1000, mean = -.2))
y = round(5 * rnorm(1000))
x[x < 0] = 0; y[y < 0] = 0
jnk = umxFactor(x); str(jnk)
df  = data.frame(x = x, y = y)
jnk = umxFactor(df); str(jnk)

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.