Installing the Required Packages install.packages(“readxl”) install.packages(“ggplot2”)
opening the Required Packages
library(readxl)
library(ggplot2)
loading DatasetA2
DatasetA2 <- read_excel("C:/Users/datta/Downloads/DatasetA2.xlsx")
creating a Contingency Table
table(DatasetA2$FavoriteDrink)
##
## Coffee Soda Tea Water
## 26 29 28 17
Creating a Bar Chart
ggplot(DatasetA2, aes(x = FavoriteDrink, fill = FavoriteDrink)) +
geom_bar() +
labs(
x = "Beverage Type",
y = "Frequency",
title = "Distribution of Beverage Preferences"
) +
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"
)
Conducting the Chi-Square Goodness-of-Fit Test
observed <- c(26, 29, 28,17)
expected <- c(0.25, 0.25, 0.25,0.25)
chisq.test(x = observed, p = expected)
##
## Chi-squared test for given probabilities
##
## data: observed
## X-squared = 3.6, df = 3, p-value = 0.308
Interpret and Report the Results
A chi-square goodness-of-fit test indicated that the observed frequencies were different/ were not different from the expected frequencies, χ²(3) = 3.6, p = 0.308.
P value 0.3>0.05 so it is not statistically significant so there is no need to calculate Effect size