Open the Installed Packages

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

Import and Name the Dataset

A5Q1 <- read_excel("C:/Users/krish/Downloads/A5Q1.xlsx")

Create a Frequency Table

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

Create a Bar Chart

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

Create the Expected Data from the given 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) since the “p-value” is statistically significant(p < 0.05).

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 [flavor] frequencies and the expected frequencies.

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

The difference was moderate, (Cohen’s W = .41).