Installing packages and loading them

library(readxl)
library(ggpubr)
## Loading required package: ggplot2
library(rcompanion)

Loading the data

data1 <- read_excel("A5Q1.xlsx")
observed <- table(data1$flavor)
observed
## 
##  Chocolate      Mango Strawberry    Vanilla 
##         87         32         57         74

Bar chart

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

Create the Expected Data

expected <- c(0.20, 0.20, 0.20, 0.40)

Conduct the Chi-Square Goodness-of-Fit Test

chi_result <- chisq.test(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 Cohen’s W (Effect Size)

w <- sqrt(as.numeric(chi_result$statistic) / sum(observed))
w
## [1] 0.4079216

A Chi-Square Goodness of Fit test was conducted to determine if there was a difference between the observed [categorical variable] frequencies and the expected frequencies.

The results showed that there was a difference between the observed and expected frequencies, χ²(df) = 41.6, p = .<0.001.

The difference was strong, (Cohen’s W = .0.41).

Therefore, the observed distribution of ice cream flavors is significantly different from the expected distribution.