Step 2: Installing packages

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

Loading the Packages

Step3:Import & Name Dataset

DatasetB2 <- read_excel("/Users/manindra/Downloads/DatasetB2 (1).xlsx")

Dataset B2 file is imported

Step 4: Create a Contingency Table

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

Step 5: Create Bar Charts

ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +               
  labs(
    x = "StudentType",
    y = "Petownership",
    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(tab)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tab
## X-squared = 0.040064, df = 1, p-value = 0.8414

Pearson’s Chi-squared test with Yates’ continuity correction data: tab X-squared = 0.040064, df = 1, p-value = 0.8414.

Interpretation The Chi-Square Test of Independence indicated there was not a significant association between student type and pet ownership, χ²(1) = 0.00, p = 1.000. Therefore, we fail to reject the null hypothesis. Student type (domestic vs. international) is not associated with pet ownership. No association between student type and pet ownership