mask_categorical: Create masked copies of categorical variables

mask.categoricalR Documentation

Create masked copies of categorical variables

Description

Creates masked copies of categorical variables.

Usage

mask.categorical(x, probability, .matrix)

Arguments

x

factor: a categorical variable (factor or ordered) with two or more categories (levels).

probability

(optional) numeric: probability that the masked copy has the same value as the original variable. Larger values correspond to weaker masking (see Details).

.matrix

(optional) matrix: masking matrix defining the probabilities of category retentions and transitions (see Details).

Details

This function creates masked copies of categorical variables. The masking model is based on a masking matrix (also called a transition matrix; Kuechenhoff et al., 2006), where the diagonal entries define the probabilities of category retentions (masked copy retains its original value), and the off-diagonal entries define the probabilities of category transitions (value on the masked copy differs from the original variable).

Either probability or .matrix (but not both) must be specified to define this matrix. The value of probability, if specified, is used for the diagonal entries in the masking matrix, and the off-diagonal entries in each row are calculated in such a way that transitions into the other categories occur with equal probabilities and the row values sum up to one. As an alternative, the .matrix argument can be used to specify the masking matrix directly.

Value

A factor with masked values.

Author(s)

Simon Grund

References

Kuechenhoff, H., Mwalili, S. M., & Lesaffre, E. (2006). A general method for dealing with misclassification in regression: The misclassification SIMEX. Biometrics, 62, 85-96. doi: 10.1111/j.1541-0420.2005.00396.x

Examples

# using 'probability'
sociosexuality <- within(sociosexuality, {
  m_sexpref <- mask.categorical(sexpref, probability = .60)
})

# equivalent specification using '.matrix'
M <- matrix(c(.60, .20, .20,
              .20, .60, .20,
              .20, .20, .60), 3, 3)

sociosexuality <- within(sociosexuality, {
  m_sexpref <- mask.categorical(sexpref, .matrix = M)
})

simongrund1/robosynth documentation built on March 20, 2022, 6:15 p.m.