#Question 1: Is there difference between the current distribution of ice cream purchases versus the expected distribution (20% chocolate, 20% strawberry, 20% mango, 40% vanilla)?

Hypotheses

Null Hypothesis (H0):

The observed ice cream flavor distribution is the same as the expected distribution.

Alternative Hypothesis (H1):

The observed ice cream flavor distribution is different from the expected distribution.Hypotheses ## R Code

# Load required libraries
library(readxl)
## Warning: package 'readxl' was built under R version 4.6.1
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.6.1
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.6.1
library(rmarkdown)
## Warning: package 'rmarkdown' was built under R version 4.6.1
#Read dataset
A5Q1 <- read_excel("A5Q1-1.xlsx")

#Create observed frequency table
observed <- table(A5Q1$flavor)
print(observed)
## 
##  Chocolate      Mango Strawberry    Vanilla 
##         87         32         57         74
#Create bar chart of observed data
barplot(observed,
        main = "Ice Cream Purchases",
        xlab = "Flavor",
        ylab = "Count",
        col = rainbow(length(observed)))

#Define expected probabilities 
# (Alphabetical order: Chocolate = 0.20, Mango = 0.20, Strawberry = 0.20, Vanilla = 0.40)
expected <- c(0.20, 0.20, 0.20, 0.40)

#Conduct Chi-Square Goodness-of-Fit Test
chi_result <- chisq.test(x = observed, p = expected)
print(chi_result)
## 
##  Chi-squared test for given probabilities
## 
## data:  observed
## X-squared = 41.6, df = 3, p-value = 4.878e-09
#Calculate effect size (Cohen's w)
w <- sqrt(as.numeric(chi_result$statistic) / sum(observed))
print(w)
## [1] 0.4079216

interpretation

A Chi-Square Goodness of Fit test was conducted to determine if there was a difference between the observed ice cream flavor frequencies and the expected frequencies. There was a significant difference between the observed and expected frequencies, chi^2(3) = 41.6, p < .001. The difference was moderate (Cohen’s w = .41).