APA Write-Up for 2x2 Chi-Square Test

Description

Generates an APA-style write up for a chi-square test of independence, with hypothesis-driven conclusions comparing expected vs. actual patterns.

Usage

apa_chi_writeup(
  chi_results_list,
  var1_name,
  var2_name,
  var1_labels = c("Level 1", "Level 2"),
  var2_labels = c("Category A", "Category B"),
  hypothesis = NULL,
  hypothesis_text = NULL,
  alpha = 0.05,
  include_descriptives = TRUE,
  table_number = NULL,
  subject = NULL
)

Arguments

chi_results_list Output from chi_square_answers().
var1_name Character. Descriptive name for row variable (e.g., "age gap between Lois and Clark").
var2_name Character. Descriptive name for column variable (e.g., "tomatometer status").
var1_labels Character vector of length 2. Labels for var1 levels (e.g., c("Small", "Big")).
var2_labels Character vector of length 2. Labels for var2 levels (e.g., c("Fresh", "Rotten")).
hypothesis

List with hypothesis details:

pattern
Character vector of length 2 specifying expected pattern for each level of var1. Use "=" for equal distribution, ">" for more likely to be var2_labels[1], "<" for more likely to be var2_labels[2]. E.g., c("=", "<") means level1 expects equal, level2 expects more of var2_labels[2].
rh_text
Optional. Full RH statement for intro.
comparison_var2_level
Which var2 level to report percentages for (1 or 2). Default 2.
hypothesis_text Character or NULL. Alternative to providing a hypothesis list. If provided, used as the rh_text in the hypothesis.
alpha Significance level. Default 0.05.
include_descriptives Logical. Currently unused, reserved for future use. Default TRUE.
table_number Integer or NULL. Optional table reference number. Default NULL.
subject Character or NULL. Subject description (e.g., "media portrayals").

Value

A character string with APA write-up.

Examples

library("psych350lab")

result <- chi_square_answers(superman, "age_grp2", "tomatometer2")

writeup <- apa_chi_writeup(
  result,
  var1_name = "age gap between Lois and Clark",
  var2_name = "tomatometer status",
  var1_labels = c("Small", "Big"),
  var2_labels = c("Fresh", "Rotten"),
  hypothesis = list(
    pattern = c("=", "<"),  # Small equal, Big more likely to be Rotten
    rh_text = paste0("media with small age gaps would be equally ",
      "likely to be Fresh or Rotten, whereas media with big age gaps would ",
      "be more likely to be rated as Rotten than Fresh by critics."),
    comparison_var2_level = 2  # Report % Rotten
  ),
  subject = "superman media"
)
cat(writeup)