ordinalize function

Convert continuous variables into ordinal variables

Convert continuous variables into ordinal variables

Allows for easy conversion of continuous variables into ordinal variables.

ordinalize( data, m = NULL, nLevels = 5, thresholds = NULL, mthresh = NULL, mord = TRUE, minOrd = 3 )

Arguments

  • data: An n x k dataframe or matrix containing only numeric values. Can also be a numeric vector.
  • m: The column number or name of the moderator variable, if applicable. Leave as NULL if there is no moderator, and set to TRUE if the moderator is the last column in the matrix or dataframe.
  • nLevels: Number of levels for the ordinal variables.
  • thresholds: List of length k, where each element is a numeric vector of length (nLevels - 1) containing the splitpoints for grouping each variable into ordered categories.
  • mthresh: Vector of length (nLevels - 1) containing thresholds to group values of the moderator into ordered categories.
  • mord: if FALSE, then the moderator will not be converted into an ordinal variable (if applicable).
  • minOrd: The minimum number of unique values allowed for each variable.

Returns

A dataframe or matrix containing the ordinalized data.

Details

If a moderator value is specified via the m argument, that variable will automatically be relegated to the last column of the resultant dataframe or matrix. It will also be renamed "M"

Examples

dat <- data.frame(sapply(1:5, function(z) rnorm(100))) ord_dat <- ordinalize(dat) # Including a moderator, without converting the moderator into an ordinal variable ord_dat <- ordinalize(dat, m = 5, mord = FALSE) colnames(dat)[5] <- 'M' ord_dat <- ordinalize(dat, m = 'M', mord = FALSE) # Use thresholds to break each variable into quartiles thresh <- lapply(dat, function(z) quantile(z, probs = c(.25, .5, .75))) ord_dat <- ordinalize(dat, thresholds = thresh)
  • Maintainer: Trevor Swanson
  • License: GPL (>= 3)
  • Last published: 2021-10-01