mask.categorical | R Documentation |
Creates masked copies of categorical variables.
mask.categorical(x, probability, .matrix)
x |
factor: a categorical variable ( |
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). |
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.
A factor with masked values.
Simon Grund
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
# 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) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.