Introduction

A restaurant sells three desserts: Chocolate Cake, Cheesecake, and Tiramisu.
The owner wants to determine whether the desserts are equally popular or if some are preferred over others.
We will use a Chi-Square Goodness-of-Fit Test to see if the observed dessert preferences match the expected proportions of 30%, 20%, and 50%.


Hypotheses


R Code

# ===============================
# CHI-SQUARE GOODNESS OF FIT TEST
# ===============================

# 1. Install and load required package
# install.packages("readxl")
library(readxl)

# 2. Import dataset
dataset <- read_excel("C:/Users/Nithin Kumar Adki/Downloads/RQ1.xlsx")  

# 3. Create a frequency table for desserts
observed <- table(dataset$Dessert)
print(observed)
## 
## Cheesecake  ChocoCake   Tiramisu 
##        171        258        119
# 4. View category names (order matters)
names(observed)
## [1] "Cheesecake" "ChocoCake"  "Tiramisu"
# 5. Define expected proportions (must add to 1 and match category order)
expected <- c(0.30, 0.20, 0.50)

# 6. Perform Chi-Square Goodness-of-Fit Test
chisq_gfit <- chisq.test(observed, p = expected)
print(chisq_gfit)
## 
##  Chi-squared test for given probabilities
## 
## data:  observed
## X-squared = 288.88, df = 2, p-value < 2.2e-16
# 7. Calculate Effect Size (Cohen's W)
W <- sqrt(chisq_gfit$statistic / sum(observed))
W
## X-squared 
## 0.7260573
# 8. Interpretation based on p-value
if (chisq_gfit$p.value < 0.05) {
  print("Significant difference — dessert preferences are NOT equally distributed.")
} else {
  print("No significant difference — dessert preferences ARE equally distributed.")
}
## [1] "Significant difference — dessert preferences are NOT equally distributed."