Opening the Required Packages

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

Importing the Dataset

DatasetB2 <- read_excel("D:/SLU/APPLIED ANALYTICS/ASSIGNMENT 5/DatasetB2.xlsx")

Creating a Contingency Table

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

Creating Bar Charts

ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +               
  labs( x = "StudentType",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)
  )

Conducting 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

Interpretation and the Results

The Chi-Square Test of Independence indicated there was not a significant association between StudentType and Petownership, χ²(1) = 0.040064, p = 0.8414. Cramer’s V (Effect Size) is not calculated as the p-value is not statistically significant.

  library(rmarkdown)