Open packages

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

Import dataset

A5Q1_1 <- read_excel("C:/Users/rteno/OneDrive - Saint Louis University/AA 5221/AA 5221-11_Assignment 5/A5Q1-1.xlsx")

Create frequency table

observed <- table(A5Q1_1$flavor) 
observed
## 
##  Chocolate      Mango Strawberry    Vanilla 
##         87         32         57         74

Create bar chart

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

Create the Expected Data

expected <- c(.20,.20,.20,.40)

Conduct the Chi-Square Goodness-of-Fit Test

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

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

Interpret and Report the Results

# 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.
# The results showed that there was a difference between the observed and expected frequencies, χ²(3) = 41.60, p < .001. 
# The difference was moderate (Cohen's W = .41).