Step 2 : load necessary packages
library(ggplot2)
library(rcompanion)
library(readxl)
Step 3: Load the dataset into R environment
datasetb2 <- read_excel("/Users/sarva/Desktop/DatasetB2.xlsx")
Step 3: import the table as an object in R
tab <- table(datasetb2$StudentType, datasetb2$PetOwnership)
Step 4: Visualising Bar Chart
p <- 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),
axis.title = element_text(size = 14),
axis.text = element_text(size = 14),
plot.title = element_text(size = 14),
legend.position = "none"
)
p
Step 5: Conducting the Chi Square Test Of Independence to determine
P-Value
chisq.test(tab)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: tab
## X-squared = 0.040064, df = 1, p-value = 0.8414
Step 6: Conduct the Cohen’s W Effect Size test
cramerV(tab)
## Cramer V
## 0.04003
#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. The association between the two variables was weak/moderate/strong (Cramer’s V = 0.04003).