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

DataSetB2 Information Research Question: Is there an association betweem student type (domestic or international) and whether or not you own a pet?

DatasetB2 <- read_excel("/Users/alexiaprudencio/Desktop/Applied Analytics 1/Assingment 5/DatasetB2.xlsx")

StudentType is represented as variable 1 and PetOwnership is represented as Variable 2

  1. Contingency Table
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
  1. Bar Chart
ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +
  labs(
    x = "StudentType",
    y = "Frequency of Pet Ownership",
    title = "PetOwnership 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")

4. 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

5 Cramer’s V (Effect Size) There is no need to report the effect size since the p-value is not statistically significant as p>0.05.

cramerV(tab)
## Cramer V 
##  0.04003
  1. Interpret and Report Results The Chi-Square Test of Independence indicated there was not a significant association between StudentType and PetOwnership, χ²(1) = 0.04, p = .841.