Last chance! 50% off unlimited learning
Sale ends in
A convenient version of mxFactor()
supporting the common
case in which the factor levels are those in the variable.
umxFactor(
x = character(),
levels = NULL,
labels = levels,
exclude = NA,
ordered = TRUE,
collapse = FALSE,
verbose = FALSE,
sep = NA
)
A variable to recode as an mxFactor (see mxFactor()
)
(default NULL). Like factor()
but UNLIKE mxFactor()
,
unique values will be used if levels not specified.
= levels (see mxFactor()
)
= NA (see mxFactor()
)
= TRUE By default return an ordered mxFactor
= FALSE (see mxFactor()
)
Whether to tell user about such things as coercing to factor
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.
Other Data Functions:
umxHetCor()
,
umx_as_numeric()
,
umx_cont_2_quantiles()
,
umx_lower2full()
,
umx_make_MR_data()
,
umx_make_TwinData()
,
umx_make_fake_data()
,
umx_make_raw_from_cov()
,
umx_polychoric()
,
umx_polypairwise()
,
umx_polytriowise()
,
umx_read_lower()
,
umx_rename()
,
umx_reorder()
,
umx_select_valid()
,
umx_stack()
,
umx
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab