Computes the deviation from the mode for a vector of frequencies of categories.

DM(x, na.rm = TRUE)

Arguments

x

a vector of frequencies

na.rm

if TRUE, missing values are removed. If FALSE, NA is returned if there is any NA value.

Value

The value of the DM statistics, which is normalised (varies between 0 and 1).

Details

According to Wilcox (1973, p. 327), 'the measure can be thought of as an index of deviation from the modal frequency, analogous to the variance as a measure of deviation from the mean'. The formula for the DM is: $$1 - \frac{\sum_{i = 1}^k (f_m - f_i)}{N(K-1)}$$

References

Wilcox, Allen R. 'Indices of Qualitative Variation and Political Measurement.' The Western Political Quarterly 26, no. 2 (1 June 1973): 325-43. doi:10.2307/446831.

Examples

x <- rmultinom(1, 100, rep_len(0.25, 4)) x <- as.vector(t(x)) names(x) <- c("a", "b", "c", "d") DM(x)
#> [1] 0.9733333
df <- rmultinom(10, 100, rep_len(0.25, 4)) df <- as.data.frame(t(df)) names(df) <- c("a", "b", "c", "d") apply(df, 1, DM)
#> [1] 0.8933333 0.8933333 0.9466667 0.9866667 0.9733333 0.9200000 0.8266667 #> [8] 0.9333333 0.9733333 0.9466667