Skip to main content

Categorical Tests

AnoFox provides 9 functions for categorical data analysis: 5 independence and goodness-of-fit tests (chi-square independence, chi-square GOF, G-test, Fisher's exact for 2x2 tables, McNemar's for paired before/after data) and 4 effect size measures (Cramer's V, Phi coefficient, contingency coefficient, Cohen's Kappa for inter-rater agreement). Fisher's exact test is the correct choice for small sample 2x2 tables where chi-square approximations break down. Cohen's Kappa returns values on a -1 to 1 scale where 0.8+ indicates almost perfect agreement between raters.

Categorical tests are statistical methods for analyzing data where variables take on discrete categories rather than continuous values. These tests determine whether observed frequencies differ significantly from expected frequencies (goodness-of-fit), whether two categorical variables are related (independence), or whether raters agree on their classifications (agreement).


Independence Tests

Chi-Square Test of Independence

Tests whether two categorical variables are associated.

Parameters

ParameterTypeRequiredDefaultDescription
row_varINTEGERYes-Row category
col_varINTEGERYes-Column category
optionsMAPNo-yates_correction (default: false)

Output

FieldTypeDescription
chi2DOUBLEChi-square statistic
p_valueDOUBLEp-value
dfBIGINTDegrees of freedom
cramers_vDOUBLEEffect size

Example

SELECT anofox_stats_chisq_test_agg(
row_var,
col_var
) as result
FROM contingency_data;

Chi-Square Goodness of Fit

Parameters

ParameterTypeRequiredDefaultDescription
observedINTEGERYes-Observed counts
expectedDOUBLEYes-Expected counts

Example

SELECT anofox_stats_chisq_gof_agg(
observed,
expected
) as result
FROM frequency_data;

G-Test (Log-Likelihood Ratio)

Alternative to chi-square, better for small samples.

Parameters

ParameterTypeRequiredDefaultDescription
row_varINTEGERYes-Row category
col_varINTEGERYes-Column category

Example

SELECT anofox_stats_g_test_agg(
row_var,
col_var
) as result
FROM data;

Fisher's Exact Test

Exact test for 2x2 tables.

Parameters

ParameterTypeRequiredDefaultDescription
row_varINTEGERYes-Row category
col_varINTEGERYes-Column category
optionsMAPNo-alternative setting

Example

SELECT anofox_stats_fisher_exact_agg(
row_var,
col_var
) as result
FROM data;

McNemar's Test

Paired categorical data (before/after).

Parameters

ParameterTypeRequiredDefaultDescription
var1INTEGERYes-Before measurement
var2INTEGERYes-After measurement
optionsMAPNo-Configuration options

Example

SELECT anofox_stats_mcnemar_agg(
var1,
var2
) as result
FROM paired_categorical;

Effect Size Measures

Quantify the magnitude of associations.

Cramér's V

Effect size for chi-square test.

SELECT anofox_stats_cramers_v_agg(row_var, col_var) as v
FROM data;

Interpretation:

V valueEffect Size
0.0 - 0.1Negligible
0.1 - 0.3Small
0.3 - 0.5Medium
> 0.5Large

Phi Coefficient

Effect size for 2x2 tables.

SELECT anofox_stats_phi_coefficient_agg(row_var, col_var) as phi
FROM data;

Contingency Coefficient

Normalized association measure.

SELECT anofox_stats_contingency_coef_agg(row_var, col_var) as c
FROM data;

Cohen's Kappa

Inter-rater agreement measure.

Parameters

ParameterTypeRequiredDefaultDescription
rater1INTEGERYes-First rater's classification
rater2INTEGERYes-Second rater's classification

Output

FieldTypeDescription
kappaDOUBLECohen's kappa (-1 to 1)
p_valueDOUBLEp-value
seDOUBLEStandard error
ci_lowerDOUBLECI lower
ci_upperDOUBLECI upper

Example

SELECT anofox_stats_cohen_kappa_agg(
rater1,
rater2
) as result
FROM rating_data;

Interpretation:

KappaAgreement
< 0Less than chance
0.0 - 0.2Slight
0.2 - 0.4Fair
0.4 - 0.6Moderate
0.6 - 0.8Substantial
0.8 - 1.0Almost perfect

Choosing a Test

ScenarioRecommended
2+ categories, large samplesChi-Square
2x2 table, small samplesFisher's Exact
Before/after paired dataMcNemar's
Prefer likelihood-basedG-Test
Quantify associationCramér's V
Rater agreementCohen's Kappa

🍪 Cookie Settings