title: ” Chi-Square_ASSIGNMENT” author: “FUZAIL” date: “2026-02-07” output: html_document ———————
knitr::opts_chunk$set(echo = TRUE)
library(readxl)
library(ggplot2)
library(rcompanion)
DatasetB2 <- read_excel("C:/Users/Student/Documents/Assignment5_AA/DatasetB2.xlsx")
#TABLE
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
print(tab)
##
## No Yes
## Domestic 27 25
## International 23 25
ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
geom_bar(position = "dodge") +
labs(
x = "Student Type",
y = "Frequency",
title = "Pet Ownership by Student Type"
) +
theme(
text = element_text(size = 14),
legend.position = "none"
)
# 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
cramerV(tab)
## Cramer V
## 0.04003
cat("The Chi-Square Test of Independence indicated there was not a significant
association between student type and pet ownership,χ²(1) = 0.04, p = .841 .
The association between the two variables was weak (Cramer's V = .04).")
## The Chi-Square Test of Independence indicated there was not a significant
## association between student type and pet ownership,χ²(1) = 0.04, p = .841 .
## The association between the two variables was weak (Cramer's V = .04).