Installing the Required Packages: install.packages(“readxl”) install.packages(“ggplot2”) install.packages(“rcompanion”)

Opening Installed Packages

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

Loading the Data set B2

DatasetB2<- read_excel("D:/DatasetB2.xlsx") 

In the DATASET A2, there is data about types of students owning pets.

Creating a Contingency Table:

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

Results are: 25 out of 52 Domestic students have pet, where as 25 out of 48 international students have pets.

PLotting a Bar Chart:

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

print(plotB2)

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

The output is:

Pearson’s Chi-squared test with Yates’ continuity correction

data: tab X-squared = 0.040064, df = 1, p-value = 0.8414

Reporting Results for Dataset B2: The Chi-Square Test of Independence indicated there was not a significant association between student type and pet ownership, χ²(1) = 0.04, p = .841.

Since the P-value is more than .05, we dont have to report the effect size by testing Cramer’s V.