This analysis is for Research Scenario 2 from Assignment 4. It tests to see if there is a “relationship between uniform design and parent”.
# INSTALL REQUIRED PACKAGE
# install.packages("readxl")
# LOAD THE PACKAGE
library(readxl)
# IMPORT THE EXCEL FILE INTO R STUDIO
dataset <- read_excel("/Users/guminhe/Downloads/RQ2.xlsx")
# =========================
# VISUALLY DISPLAY THE DATA
# =========================
# PURPOSE
# Visually display the data.
# A frequency table can be used instead of a bar graph to visually display the data.
# CREATE A FREQUENCY TABLE
contingencytable <- table(dataset$Parent, dataset$Preferred_Design)
print(contingencytable)
##
## A B
## Father 21 29
## Mother 31 19
# ====================================
# CHI-SQUARE TEST OF INDEPENDENCE CODE
# ====================================
# PURPOSE
# Determine if the null or alternate hypothesis was supported.
# CONDUCT THE TEST
chisq_indep <- chisq.test(contingencytable)
print(chisq_indep)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: contingencytable
## X-squared = 3.2452, df = 1, p-value = 0.07163
# DETERMINE STATISTICAL SIGNIFICANCE
# ================
# EFFECT SIZE CODE (No need for this)
# ================
# PURPOSE
# Determine how strong the relationship was between the two variables.
# INSTALL REQUIRED PACKAGE
# install.packages("lsr")
# LOAD THE PACKAGE
library(lsr)
# CALCULATE CRAMER'S V
cramers_v <- cramersV(contingencytable)
cat("Cramer's V (effect size):", round(cramers_v, 3), "\n")
## Cramer's V (effect size): 0.18