Learn R Programming

rcompanion (version 1.13.2)

cramerVFit: Cramer's V for chi-square goodness-of-fit tests

Description

Calculates Cramer's V for a vector of counts and expected counts.

Usage

cramerVFit(x, p = rep(1/length(x), length(x)), digits = 4, ...)

Arguments

x

A vector of observed counts.

p

A vector of expected or default probabilities.

digits

The number of significant digits in the output.

...

Additional arguments passed to chisq.test.

Value

A single statistic, Cramer's V.

Details

In the case of single vector of counts and expected probabilities, a modification of Cramer's V can be used to indicate the degree of deviation from the expected probabilities.

It is not affected by sample size and can be used as an effect size.

In the case of equally-distributed expected frequencies, Cramer's V will be equal to 1 when all counts are in one category, and it will be equal to 0 when the counts are equally distributed across categories.

References

http://rcompanion.org/handbook/H_03.html

See Also

cramerV

Examples

Run this code
# NOT RUN {
### Equal probabilities example
### From http://rcompanion.org/handbook/H_03.html
nail.color = c("Red", "None", "White", "Green", "Purple", "Blue")
observed   = c( 19,    3,      1,       1,       2,        2    )
expected   = c( 1/6,   1/6,    1/6,     1/6,     1/6,      1/6  )
chisq.test(x = observed, p = expected)
cramerVFit(x = observed, p = expected)

### Unequal probabilities example
### From http://rcompanion.org/handbook/H_03.html
race = c("White", "Black", "American Indian", "Asian", "Pacific Islander",
          "Two or more races")
observed = c(20, 9, 9, 1, 1, 1)
expected = c(0.775, 0.132, 0.012, 0.054, 0.002, 0.025)
chisq.test(x = observed, p = expected)
cramerVFit(x = observed, p = expected)

### Examples of perfect and zero fits
cramerVFit(c(100, 0, 0, 0, 0))
cramerVFit(c(10, 10, 10, 10, 10))

# }

Run the code above in your browser using DataLab