This document walks through a Chi-Square Test of Independence to check whether there is a relationship between a student’s status (Domestic vs. International) and whether they received a scholarship (0 = No, 1 = Yes).
You only need to run this once on your computer. After the packages are installed, you can turn this chunk off (or delete it) so it doesn’t reinstall every time.
install.packages("readxl")
install.packages("TH.Tools") - Because I couldn't download rcompanion without it!
install.packages("rcompanion")
install.packages("ggplot2")
Every time you start a new R session, you need to load the packages (even if they’re already installed).
library(readxl)
library(rcompanion)
library(ggplot2)
This reads in your Excel file. Update the file path below to match where the file is saved on your computer.
A4Q2 <- read_excel("C:/Users/CHEENA/Downloads/A4Q2.xlsx")
We use table() to count how many students fall into each
combination of status and scholarship.
polit_table <- table(A4Q2$status, A4Q2$scholarship)
polit_table
##
## 0 1
## Domestic 39 111
## International 118 32
A bar plot makes it easier to see the pattern at a glance.
barplot(polit_table,
beside = TRUE,
col = rainbow(nrow(polit_table)),
legend = rownames(polit_table))
The Chi-Square Test of Independence tells us whether
status and scholarship are related, or whether
any difference we see is just due to chance.
chi_result <- chisq.test(polit_table)
chi_result
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: polit_table
## X-squared = 81.297, df = 1, p-value < 2.2e-16
The Chi-Square test tells us if there’s a relationship, but not how strong it is. Cramer’s V gives us that effect size.
rcompanion::cramerV(polit_table)
## Cramer V
## 0.5272
Using the numbers from the outputs above, here’s how you can report the results in APA style:
A Chi-Square Test of Independence was conducted to determine if there was an association between student status (Domestic vs. International) and scholarship receipt.
The results showed that there was an association between the two variables, χ²(1) = 81.30, p < .001.
The association was large, (Cramer’s V = .53).
| What to report | Where to find it |
|---|---|
| df | df value in the chi-square output |
| χ² value | X-squared value in the chi-square output |
| p-value | p-value in the chi-square output (if it’s a tiny number
like 2.2e-16, just write p < .001) |
| Cramer’s V | The number printed under Cramer V |
| Effect size label | .10 = small, .30 = medium, .50 = large (for a 2x2 table) |
| “was” / “was not” | “was” if p < .05, “was not” if p ≥ .05 |