Step 1 opening the installed packages
install.packages("readxl")
## Installing package into 'C:/Users/pavan/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'readxl'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\pavan\AppData\Local\R\win-library\4.5\00LOCK\readxl\libs\x64\readxl.dll
## to C:\Users\pavan\AppData\Local\R\win-library\4.5\readxl\libs\x64\readxl.dll:
## Permission denied
## Warning: restored 'readxl'
##
## The downloaded binary packages are in
## C:\Users\pavan\AppData\Local\Temp\Rtmp0gQVSb\downloaded_packages
install.packages("ggplot2")
## Installing package into 'C:/Users/pavan/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'ggplot2' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pavan\AppData\Local\Temp\Rtmp0gQVSb\downloaded_packages
install.packages("rcompanion")
## Installing package into 'C:/Users/pavan/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'rcompanion' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pavan\AppData\Local\Temp\Rtmp0gQVSb\downloaded_packages
Step 2 Open the Required Packages
library(readxl)
library(ggplot2)
library(rcompanion)
Step 3: Import & Name Dataset
DatasetB2 <- read_excel("C:/Users/pavan/Desktop/DatasetB2.xlsx")
Step 4: Create a Contingency Table
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
tab
##
## No Yes
## Domestic 27 25
## International 23 25
Step 5: Create 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),
legend.position = "none"
)
Step 6: Conduct 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
Step 7: Cramer’s V (Effect Size)
cramerV(tab)
## Cramer V
## 0.04003
Results:The Chi-Square Test of Independence indicated there was not a significant association between Variable A and Variable B,χ²(1) = 0.04, p = .841. The association between the two variables was weak (Cramér’s V = .04).