Research Question: Do students prefer tea, coffee, water, and soda equally? title: Chi-Square Goodness-of-Fit Test
Dataset A Step 1: Install Required Packages (run once) install.packages(“readxl”) install.packages(“ggplot2”)
Step 2: Open Installed Packages
library(readxl)
library(ggplot2)
library(rcompanion)
Step 3: Import and Name Dataset
DatasetA2 <- read_excel("C:/Users/spvar/Downloads/DatasetA2.xlsx")
Step 4: Create Frequency Table
table(DatasetA2$FavoriteDrink)
##
## Coffee Soda Tea Water
## 26 29 28 17
Step 5: Create Bar Chart
ggplot(DatasetA2, aes(x = FavoriteDrink)) +
geom_bar() +
labs(x = "Favorite Drink", y = "Frequency")
Interpretation: The bar chart shows that tea, coffee, and soda were
chosen at similar frequencies, while water was chosen less often.
However, the differences across categories appear small, which is
consistent with the non-significant chi-square goodness-of-fit result.
Step 6: Conduct Chi-Square Goodness-of-Fit Test
observed <- table(DatasetA2$FavoriteDrink)
expected <- c(1/4, 1/4, 1/4, 1/4)
chisq.test(x = observed, p = expected)
##
## Chi-squared test for given probabilities
##
## data: observed
## X-squared = 3.6, df = 3, p-value = 0.308
Step 7: Interpretation A chi-square goodness-of-fit test indicated that the observed frequencies were / were not different from the expected frequencies, χ²(df) = 3.6, p = 0.308
A Chi-Square Goodness-of-Fit test was conducted to determine whether students prefer tea, coffee, soda, and water equally. The results indicated that there was no statistically significant difference between the observed and expected frequencies, χ²(3) = 3.60, p = .308.
Because the p-value was greater than .05, we fail to reject the null hypothesis.
Therefore, there is no significant difference in students’ beverage preferences. Students appear to prefer tea, coffee, soda, and water at approximately equal rates.