umx_cont_2_quantiles: umx_cont_2_quantiles

umx_cont_2_quantilesR Documentation

umx_cont_2_quantiles

Description

Recode a continuous variable into n-quantiles (default = deciles (10 levels)). It returns an OpenMx::mxFactor(), with the levels labeled with the max value in each quantile (i.e., open on the left-side). quantiles are labeled "quantile1" "quantile2" etc.

Usage

umx_cont_2_quantiles(
  x,
  nlevels = NULL,
  type = c("mxFactor", "ordered", "unordered"),
  verbose = FALSE,
  returnCutpoints = FALSE
)

Arguments

x

a variable to recode as ordinal (email maintainer("umx") if you'd like this upgraded to handle df input)

nlevels

How many bins or levels (at most) to use (i.e., 10 = deciles)

type

what to return (Default is "mxFactor") options: "ordered" and "unordered")

verbose

report the min, max, and decile cuts used (default = FALSE)

returnCutpoints

just return the cutpoints, for use directly

Details

Note: Redundant quantiles are merged. i.e., if the same score identifies all deciles up to the fourth, then these will be merged into one bin, labeled "quantile4".

Value

  • recoded variable as an OpenMx::mxFactor()

References

See Also

Other Data Functions: noNAs(), prolific_anonymize(), prolific_check_ID(), prolific_read_demog(), umx, umxFactor(), umxHetCor(), umx_as_numeric(), umx_lower2full(), umx_make_MR_data(), umx_make_TwinData(), umx_make_fake_data(), umx_make_raw_from_cov(), umx_merge_randomized_columns(), umx_polychoric(), umx_polypairwise(), umx_polytriowise(), umx_read_lower(), umx_rename(), umx_reorder(), umx_score_scale(), umx_select_valid(), umx_stack(), umx_strings2numeric()

Examples

x = umx_cont_2_quantiles(rnorm(1000), nlevels = 10, verbose = TRUE)
x = data.frame(x)
str(x); levels(x)
table(x)
## Not run: 
ggplot2::qplot(x$x)
y = mxDataWLS(x, type = "WLS")

## End(Not run)

# ===========================
# = Use with twin variables =
# ===========================

data(twinData)
x = twinData
cuts  = umx_cont_2_quantiles(rbind(x$wt1, x$wt2) , nlevels = 10, returnCutpoints = TRUE)
x$wt1 = umx_cont_2_quantiles(x$wt1, nlevels = cuts) # use same for both...
x$wt2 = umx_cont_2_quantiles(x$wt2, nlevels = cuts) # use same for both...
str(x[, c("wt1", "wt2")])

# More examples

x = umx_cont_2_quantiles(mtcars[, "mpg"], nlevels = 5) # quintiles
x = umx2ord(mtcars[, "mpg"], nlevels = 5) # using shorter alias
x = umx_cont_2_quantiles(mtcars[, "cyl"], nlevels = 10) # more levels than integers exist
x = umx_cont_2_quantiles(rbinom(10000, 1, .5), nlevels = 2)

tbates/umx documentation built on Dec. 14, 2024, 11:28 a.m.