library(readxl)
library(ggpubr)
## Loading required package: ggplot2
library(rmarkdown)
#I added the library(ggpubr) and the library(rmarkdown) because those were not there, but I don't remember them being in the original assignment directions.
A4Q1 <- read_excel("C:/Users/annke/OneDrive - Saint Louis University/AA 5221/Assignment 4/A4Q1.xlsx")
observed <-table(A4Q1$flavor)
observed
##
## Chocolate Mango Strawberry Vanilla
## 87 32 57 74
barplot(observed,
main = "Ice Cream Purchases",
xlab = "Flavor",
ylab = "Count",
col = rainbow(length(observed)))

#I changed the word flavors to purchases in the main and the word flavors to flavor in the xlab.
#My labels did not match your wording exactly, although it was close. I was not sure if the title and the xlab had to match your answer key exactly or if I could keep them what I named them, but just to be sure I changed them.
expected <- c(.20, .20, .20, .40)
chi_result <- chisq.test(x = observed, p = expected)
chi_result
##
## Chi-squared test for given probabilities
##
## data: observed
## X-squared = 41.6, df = 3, p-value = 4.878e-09
w <- sqrt(as.numeric(chi_result$statistic) / sum(observed))
w
## [1] 0.4079216
#I added the Cohen's W formula to calculate the effect size the results are statistically significant.
# I deleted my original interpretation that incorrectly noted the results were not statistically significant because they are.
# A Chi-Square Goodness-of-Fit test was conducted to determine if there was a difference between the observed Ice Cream Flavors frequencies and the expected frequencies.
# The results showed that there was a difference between the observed and expected frequencies, x2(3) = 41.6, p < .001.
#I changed the p-value to show that it was actually less than .001
#I changed this because I must have looked it it wrong and wrote that p was more than .05, but it is not.
#The difference was moderate, (Cohen's W = .41).