##https://rpubs.com/anup0stha/1397893

library(readxl) 
library(ggplot2) 
library(rcompanion)
DatasetB2 <- read_excel('/Volumes/Anup/SLU/3rd Sem/Applied Analytics/Asignment5/DatasetB2.xlsx')

Creating a Contingency Table

tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)

Creating Bar Charts

ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +                 
  labs(
    x = "Student Type",
    y = "Frequency",
    title = "Pet Ownetship By Student Type"
  ) +
  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

The Chi-Square Test of Independence indicated there was not a significant association between Student Type and Pet Ownership, χ²(df) = 0.040064, p = 0.8414