Importing library

library(readxl)
library(ggplot2)
library(rcompanion)

Import DatasetA2

DatasetA2 <- read_excel("C:/Users/Admin/Downloads/DatasetA2.xlsx")

Check Variable Names

names(DatasetA2)
## [1] "StudentID"     "FavoriteDrink"

Frequency Table (Observed Counts)

table(DatasetA2$FavoriteDrink)
## 
## Coffee   Soda    Tea  Water 
##     26     29     28     17

Bar Chart

ggplot(DatasetA2, aes(x = FavoriteDrink, fill = FavoriteDrink)) +
  geom_bar() +
  labs(
    x = "Favorite Drink",
    y = "Frequency",
    title = "Distribution of Favorite Drink"
  ) +
  theme(
    text = element_text(size = 14),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 14),
    plot.title = element_text(size = 14),
    legend.position = "none"
  )

Chi-Square Goodness-of-Fit Test

observed <- as.vector(table(DatasetA2$FavoriteDrink))
expected <- rep(0.25, 4)

chisq.test(x = observed, p = expected)
## 
##  Chi-squared test for given probabilities
## 
## data:  observed
## X-squared = 3.6, df = 3, p-value = 0.308

Interpretation

A chi-square goodness-of-fit test indicated that the observed frequencies were not significantly different from the expected frequencies, χ²(3) = 3.60, p = 0.308.