Open the Installed Packages
library(readxl)
library(ggplot2)
library(rcompanion)
Import and Name Dataset
DatasetB2 <- read_excel("C:/Users/cniti/Documents/AA-5221 Applied Analytics/DatasetB2.xlsx")
Create a Contingency Table
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
Create Bar Charts
ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
geom_bar(position = "dodge") +
labs(
x = "StudentType",
y = "Frequency",
title = "Pet Ownership by Students"
) +
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"
)
Conduct the Chi-Square Test of Independence
chisq.test(tab)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: tab
## X-squared = 0.040064, df = 1, p-value = 0.8414
Cramer’s V (Effect Size)
cramerV(tab)
## Cramer V
## 0.04003
The Chi-Square Test of Independence indicated there was/ was not a significant association between gender and voting behavior, χ²(1) = 0.040, p = .8414.The association between the two variables was moderate (Cramer’s V = 0.04003).