Step 1: Import and load necessary packages
library(readxl)
library(ggplot2)
library(rcompanion)
Step 2: Load the dataset into R environment
datasetA2 <- read_excel("/Users/sarva/Desktop/DatasetA2.xlsx")
Step 3: Creating a frequency table with the provided dataset
table(datasetA2$FavoriteDrink)
##
## Coffee Soda Tea Water
## 26 29 28 17
Step 4 : Creating a bar chart
ggplot(datasetA2, aes(x = FavoriteDrink, fill = FavoriteDrink)) +
geom_bar() +
labs(
x = "favorite drink",
y = "Frequency",
title = "Distribution of Favourite 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"
)
Step 5 : Conduct the Chi Square test of goodness
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
cramerV (observed, correct=FALSE)