library(readxl)
A4Q1 <- read_excel("C:/Users/onhau01/Desktop/R-Revision/A4Q1.xlsx")

#Create and View an observed frequency Table
table(A4Q1$flavor)
## 
##  Chocolate      Mango Strawberry    Vanilla 
##         87         32         57         74
observed <-table(A4Q1$flavor)

observed
## 
##  Chocolate      Mango Strawberry    Vanilla 
##         87         32         57         74
##  Chocolate      Mango Strawberry    Vanilla  

##         87         32         57         74 

#Create a Bar Chart of observed data

barplot(observed,
main = "Ice Cream Purchases",
xlab = "flavor",
ylab = "Count",
col = rainbow(length(observed)))

#I corrected the title of the Plot from Flavor to Icecream purchases.

#Calculate Goodness-of-Fit Test
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
#Calculate the Effect Size (Cohen's W)
w <- sqrt(as.numeric(chi_result$statistic) / sum(observed))
w
## [1] 0.4079216
#Reporting the Results:
# A Chi-Square Goodness-of-Fit test was conducted to determine if there was a difference between observed ice cream flavor frequencies and the expected frequencies.
# The results showed that there was a significant difference between the observed and expected frequencies, χ²(3) = 41.6, p < .001.
# The difference was moderate  (Cohen's W = .41.).


#I corrected on reporting the results, Instead of using the word "variable" i specified the actual name of the variable "ice cream flavor ".