Load Packages
library(readxl)
library(ggplot2)
library(rcompanion)
Importing Datasets
DatasetB2 <- read_excel("/Users/karim/Desktop/DatasetB2.xlsx")
head(DatasetB2)
## # A tibble: 6 × 3
## StudentID StudentType PetOwnership
## <dbl> <chr> <chr>
## 1 1 Domestic No
## 2 2 Domestic No
## 3 3 Domestic No
## 4 4 International Yes
## 5 5 Domestic No
## 6 6 International No
Create Contingency Table
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
tab
##
## No Yes
## Domestic 27 25
## International 23 25
Create Grouped Bar Chart
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)
)
Chi-Square Test of Independence
chi_result <- chisq.test(tab)
chi_result
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: tab
## X-squared = 0.040064, df = 1, p-value = 0.8414
Effect Size (Cramer’s V)
cramerV(tab)
## Cramer V
## 0.04003
Interpretation The Chi-Square Test of Independence showed that there was no significant relationship between student type and pet ownership, χ²(1) = 0.04, p = 0.841. Thus, we fail to reject the null hypothesis. This implies that there is no relationship between student type (domestic or international) and pet ownership.