Scenario 1 — Chi-Square Goodness-of-Fit (Desserts)

Install once if needed:

install.packages(“readxl”)

library(readxl)

— Import the Excel (use ONE of these) —

A) Forward slashes

dataset <- read_excel(“C:/Users/goud4/Desktop/RQ1.xlsx”)

B) OR doubled backslashes

dataset <- read_excel(“C:\Users\goud4\Desktop\RQ1.xlsx”)

C) OR file picker (no path typing)

dataset <- read_excel(file.choose())

— Frequency table of your dessert column —

observed <- table(dataset$Dessert) print(observed) names(observed) # see the order of categories

— Expected proportions —

If you want equal expectation across whatever categories are present:

expected <- rep(1/length(observed), length(observed))

If your assignment expects 30%, 20%, 50% for

Cheesecake, ChocoCake, Tiramisu (be sure order matches observed):

expected_named <- c(Cheesecake = 0.30, ChocoCake = 0.20, Tiramisu = 0.50) expected <- as.numeric(expected_named[names(observed)]) # aligns by name

— Chi-square test —

chisq_gfit <- chisq.test(observed, p = expected) print(chisq_gfit)

— Effect size (Cohen’s W) —

W <- sqrt(as.numeric(chisq_gfit$statistic) / sum(observed)) W

— Summary you can paste into RPubs —

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 ))

Scenario 1 — Chi-Square Goodness-of-Fit (Desserts)

========================================

CHI-SQUARE TEST OF INDEPENDENCE

========================================

— Load package —

if (!requireNamespace(“readxl”, quietly = TRUE)) install.packages(“readxl”) library(readxl)

— Import your Excel file —

Option 1: Direct path (use forward slashes)

dataset <- read_excel(“C:/Users/goud4/Desktop/RQ2.xlsx”)

Option 2 (easier): use file picker

dataset <- read_excel(file.choose())

— Check column names —

cat(“Columns in dataset:”, paste(names(dataset), collapse = “,”), “”)

Example columns: Parent, Preferred_Design

Make sure these names exactly match your file

contingencytable <- table(dataset\(Parent, dataset\)Preferred_Design) print(contingencytable)

====================================

CHI-SQUARE TEST OF INDEPENDENCE CODE

====================================

chisq_indep <- chisq.test(contingencytable) print(chisq_indep)

==========================

EFFECT SIZE (Cramér’s V)

==========================

Compute manually (no extra packages needed)

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))

==========================

AUTO SUMMARY (Copy for RPubs)

==========================

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)

Interpret effect size

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