Chi-Square Test of Independence Research Question:

Step 1: Open Installed Packages

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

Step 2: Import and Name Dataset

DatasetB2 <- read_excel("C:/Users/Siddhu Yeluri/Downloads/DatasetB2.xlsx")

Step 3: Create a Contingency Table

table(DatasetB2$StudentType, DatasetB2$PetOwnership)
##                
##                 No Yes
##   Domestic      27  25
##   International 23  25

Step 4: Create Bar Charts

ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +
  labs(x = "Student Type", 
       y = "Frequency",
       title = "PetOwnership by StudentType") +
  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 6: Conduct the Chi-Square Test of Independence

chisq.test(DatasetB2$StudentType, DatasetB2$PetOwnership)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  DatasetB2$StudentType and DatasetB2$PetOwnership
## X-squared = 0.040064, df = 1, p-value = 0.8414