── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
Two-sample test of proportions
Compute a two-sample proportions test. General form is prop.test(x, n, p = NULL, alternative = “two.sided”, correct = TRUE) where X is a vector of success counts, n is a vector of total counts, alternative indicates the alternative hypothesis, and correct = a logical indicating whether Yates’ correction should be used where possible.
NOTE - This gives you a Chi-squared, but if you use correct = FALSE, the square root of the Chi-squared value = Z.
We can also get Cramer’s v, which operates like an R-squared to measure the strength of the association. (1) Install the package “vcd” if you have not done so, and library it.
library(vcd)
Loading required package: grid
Then run the command assocstats on the data table to get Cramer’s V. Note this gives you the Chi-squared test again, and some other measures of association.