Cohen's w (omega)
cohenW.RdCalculates Cohen's w for a table of nominal variables.
Usage
cohenW(
x,
y = NULL,
p = NULL,
ci = FALSE,
conf = 0.95,
type = "perc",
R = 1000,
histogram = FALSE,
digits = 4,
reportIncomplete = FALSE,
...
)Arguments
- x
Either a two-way table or a two-way matrix. Can also be a vector of observations for one dimension of a two-way table.
- y
If
xis a vector,yis the vector of observations for the second dimension of a two-way table.- p
If
xis a vector of observed counts,pcan be given as a vector of theoretical probabilties, as in a chi-square goodness of fit test.- ci
If
TRUE, returns confidence intervals by bootstrap. May be slow.- conf
The level for the confidence interval.
- type
The type of confidence interval to use. Can be any of "
norm", "basic", "perc", or "bca". Passed toboot.ci.- R
The number of replications to use for bootstrap.
- histogram
If
TRUE, produces a histogram of bootstrapped values.- digits
The number of significant digits in the output.
- reportIncomplete
If
FALSE(the default),NAwill be reported in cases where there are instances of the calculation of the statistic failing during the bootstrap procedure. In the case of the goodness-of-fit scenario, setting this toTRUEwill have no effect.- ...
Additional arguments passed to
chisq.test.
Value
A single statistic, Cohen's w. Or a small data frame consisting of Cohen's w, and the lower and upper confidence limits.
Details
Cohen's w is used as a measure of association between two nominal variables, or as an effect size for a chi-square test of association. For a 2 x 2 table, the absolute value of the phi statistic is the same as Cohen's w. The value of Cohen's w is not bound by 1 on the upper end.
Cohen's w is "naturally nondirectional". That is,
the value will always be zero or positive.
Because of this, if type="perc",
the confidence interval will
never cross zero.
The confidence interval range should not
be used for statistical inference.
However, if type="norm", the confidence interval
may cross zero.
When w is close to 0 or very large, or with small counts, the confidence intervals determined by this method may not be reliable, or the procedure may fail.
References
https://rcompanion.org/handbook/H_10.html
Cohen J. 1992. "A Power Primer". Psychological Bulletin 12(1): 155-159.
Cohen, J. 1988. Statistical Power Analysis for the Behavioral Sciences, 2nd Ed. Routledge.
Author
Salvatore Mangiafico, mangiafico@njaes.rutgers.edu
Examples
### Example with table
data(Anderson)
fisher.test(Anderson)
#>
#> Fisher's Exact Test for Count Data
#>
#> data: Anderson
#> p-value = 0.000668
#> alternative hypothesis: two.sided
#>
cohenW(Anderson)
#> Cohen w
#> 0.4387
### Example for goodness-of-fit
### Bird foraging example, Handbook of Biological Statistics
observed = c(70, 79, 3, 4)
expected = c(0.54, 0.40, 0.05, 0.01)
chisq.test(observed, p = expected)
#> Warning: Chi-squared approximation may be incorrect
#>
#> Chi-squared test for given probabilities
#>
#> data: observed
#> X-squared = 13.593, df = 3, p-value = 0.003514
#>
cohenW(observed, p = expected)
#> Cohen w
#> 0.2952
### Example with two vectors
Species = c(rep("Species1", 16), rep("Species2", 16))
Color = c(rep(c("blue", "blue", "blue", "green"),4),
rep(c("green", "green", "green", "blue"),4))
fisher.test(Species, Color)
#>
#> Fisher's Exact Test for Count Data
#>
#> data: Species and Color
#> p-value = 0.01211
#> alternative hypothesis: true odds ratio is not equal to 1
#> 95 percent confidence interval:
#> 1.463598 60.596055
#> sample estimates:
#> odds ratio
#> 8.279362
#>
cohenW(Species, Color)
#> Cohen w
#> 0.5