library(readxl)
dataset <- read_excel(“C:/Users/goud4/Desktop/RQ1.xlsx”)
observed <- table(dataset$Dessert) print(observed) names(observed) # see the order of categories
expected_named <- c(Cheesecake = 0.30, ChocoCake = 0.20, Tiramisu = 0.50) expected <- as.numeric(expected_named[names(observed)]) # aligns by name
chisq_gfit <- chisq.test(observed, p = expected) print(chisq_gfit)
W <- sqrt(as.numeric(chisq_gfit$statistic) / sum(observed)) W
N <- sum(observed) df <- as.numeric(chisq_gfit\(parameter) chi<- as.numeric(chisq_gfit\)statistic) p <- chisq_gfit$p.value p_txt <- if (p < .001) “< .001” else sprintf(“%.3f”, p) top_cat <- names(observed)[which.max(observed)] cat(sprintf( “Chi-Square Goodness-of-Fit Test examined dessert preferences across %d categories.%s a statistically %s difference, χ²(%d, N = %d) = %.2f, p = %s.most selected dessert was %s. Effect size: Cohen’s W = %.2f.”, length(observed), ifelse(p < .05, “was”, “was not”), ifelse(p < .05, “significant”, “non-significant”), df, N, chi, p_txt, top_cat, W ))
if (!requireNamespace(“readxl”, quietly = TRUE)) install.packages(“readxl”) library(readxl)
dataset <- read_excel(“C:/Users/goud4/Desktop/RQ2.xlsx”)
cat(“Columns in dataset:”, paste(names(dataset), collapse = “,”), “”)
contingencytable <- table(dataset\(Parent, dataset\)Preferred_Design) print(contingencytable)
chisq_indep <- chisq.test(contingencytable) print(chisq_indep)
n <- sum(contingencytable) r <- nrow(contingencytable) c <- ncol(contingencytable) V <- sqrt(as.numeric(chisq_indep$statistic) / (n * min(r - 1, c - 1)))
cat(sprintf(“Cramér’s V (effect size): %.3f”, V))
df <- as.numeric(chisq_indep\(parameter) chi <- as.numeric(chisq_indep\)statistic) p <- chisq_indep$p.value p_txt <- if (p < .001) “< .001” else sprintf(“%.3f”, p)
if (df == 1) { V_label <- ifelse(V < .10, “negligible”, ifelse(V < .30, “small”, ifelse(V < .50, “medium”, “large”))) } else if (df == 2) { V_label <- ifelse(V < .07, “negligible”, ifelse(V < .21, “small”, ifelse(V < .35, “medium”,_
print(contingencytable)
A B
Father 21 29 Mother 31 19 > > # ==================================== > # CHI-SQUARE TEST OF INDEPENDENCE CODE > # ==================================== > > 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