Suppose you are drawing samples from a population of categorical variables. Given samples s1 and s2, I want to calculate an index that would tell me how close I am to the ideal situation where all elements of the sample are equal to each other:
# Given the two samples pop <- c("A", "B", "C") set.seed(10) s1 <- sample(c("A", "B", "C"), 10, rep=T) s2 <- sample(c("A", "B", "C"), 10, rep=T) # Suppose also that s3 = c("A", "A", "A") # and s4 = c("A", "B", "C")
Basically I'd like to find and index f that when applied to a vector with high "variance" such as s4 gives a maximum (or minimum) value and when applied to a vector of characters with low "variance" such as s3 gives a minimum (or maximum) value.
What can I use? I know that in R I can convert factors to numbers using ther number level encoding, then I could calculate the variance, but I'm not sure this is is the method I'd like to use.