Skip to contents

Cochran's Q test for analyzing paired categorical (binary) data with more than two time points or conditions. This is the extension of McNemar's test for repeated measures with binary outcomes, commonly used in clinical studies to test for changes in treatment response or diagnostic agreement across multiple time points.

Usage

cochranq(
  data,
  variables,
  id,
  method = "asymptotic",
  alpha = 0.05,
  posthoc = TRUE,
  correction = "bonferroni",
  effect_size = TRUE,
  confidence_level = 0.95,
  show_pattern = TRUE,
  show_assumptions = TRUE,
  clinical_interpretation = TRUE
)

Arguments

data

the data as a data frame

variables

Binary variables measured at different time points or conditions (minimum 3 variables required)

id

Optional subject identifier for paired data structure validation

method

Method for calculating p-values

alpha

Alpha level for hypothesis testing

posthoc

Perform pairwise post-hoc comparisons when Q test is significant

correction

Multiple comparison correction method for post-hoc tests

effect_size

Include effect size measures (Kendall's W coefficient of concordance)

confidence_level

Confidence level for confidence intervals

show_pattern

Show detailed response pattern analysis and frequencies

show_assumptions

Test assumptions for Cochran's Q test validity

clinical_interpretation

Provide clinical interpretation guidance for results

Value

A results object containing:

results$instructionsa html
results$dataInfoa table
results$cochranQTesta table
results$effectSizea table
results$responsePatternsa table
results$pairwiseComparisonsa table
results$marginalFrequenciesa table
results$assumptionTestinga table
results$clinicalInterpretationa table
results$responsePatternPlotan image
results$marginalProportionsPlotan image
results$pairwiseComparisonPlotan image
results$methodExplanationa html

Tables can be converted to data frames with asDF or as.data.frame. For example:

results$dataInfo$asDF

as.data.frame(results$dataInfo)

Examples