library(readxl)
library(ggplot2)
library(rcompanion)
DatasetA2 <- read_excel("/Users/asfia/Desktop/DatasetA2.xlsx")
# Frequency Table
table(DatasetA2$FavoriteDrink)
##
## Coffee Soda Tea Water
## 26 29 28 17
# Bar Chart Plot
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"
)
observed <- c(26, 29, 28, 17) expected <- c(0.25, 0.25, 0.25, 0.25) chisq.test(x = observed, p = expected) ```
Interpretation: A chi-square goodness-of-fit test indicated that the observed frequencies were not different from the expected frequencies, χ²(3) = 3.60, p = .308.