Skip to main content

Correlation Tests

Test and estimate correlations between variables.


Linear Correlation

Pearson Correlation

Linear correlation with significance test.

Parameters

ParameterTypeRequiredDefaultDescription
xDOUBLEYes-First variable
yDOUBLEYes-Second variable
optionsMAPNo-Configuration options

Output

FieldTypeDescription
rDOUBLEPearson correlation (-1 to 1)
p_valueDOUBLEp-value
t_statisticDOUBLEt-statistic
ci_lowerDOUBLECI lower bound
ci_upperDOUBLECI upper bound
nBIGINTSample size

Example

SELECT anofox_stats_pearson_agg(x, y) as result
FROM data;

Interpretation:

r valueStrength
0.0 - 0.3Weak
0.3 - 0.7Moderate
0.7 - 1.0Strong

Rank Correlations

Spearman Rank Correlation

Monotonic relationship (robust to outliers).

Parameters

ParameterTypeRequiredDefaultDescription
xDOUBLEYes-First variable
yDOUBLEYes-Second variable
optionsMAPNo-Configuration options

Output

FieldTypeDescription
rhoDOUBLESpearman's rho
p_valueDOUBLEp-value
nBIGINTSample size

Example

SELECT anofox_stats_spearman_agg(x, y) as result
FROM data;

Kendall's Tau

Rank correlation (handles ties well).

Parameters

ParameterTypeRequiredDefaultDescription
xDOUBLEYes-First variable
yDOUBLEYes-Second variable
optionsMAPNo-Configuration options

Output

FieldTypeDescription
tauDOUBLEKendall's tau
p_valueDOUBLEp-value
nBIGINTSample size

Example

SELECT anofox_stats_kendall_agg(x, y) as result
FROM data;

Nonlinear Correlation

Distance Correlation

Detects nonlinear relationships.

Parameters

ParameterTypeRequiredDefaultDescription
xDOUBLEYes-First variable
yDOUBLEYes-Second variable

Output

FieldTypeDescription
dcorDOUBLEDistance correlation (0 to 1)
dcovDOUBLEDistance covariance
nBIGINTSample size

Example

SELECT anofox_stats_distance_cor_agg(x, y) as result
FROM data;

Key property: Distance correlation = 0 if and only if X and Y are independent (unlike Pearson which only detects linear relationships).


Reliability Measures

Intraclass Correlation (ICC)

Reliability/agreement between raters.

Parameters

ParameterTypeRequiredDefaultDescription
valueDOUBLEYes-Rating value
rater_idINTEGERYes-Rater identifier
subject_idINTEGERYes-Subject identifier
optionsMAPNo-Model configuration

Options MAP:

OptionTypeDefaultDescription
modelVARCHARtwo_way_randomone_way, two_way_random, two_way_mixed

Example

SELECT anofox_stats_icc_agg(
value,
rater_id,
subject_id,
MAP {'model': 'two_way_random'}
) as result
FROM rating_data;

Interpretation:

ICC valueReliability
< 0.5Poor
0.5 - 0.75Moderate
0.75 - 0.9Good
> 0.9Excellent

Choosing a Correlation Method

ScenarioRecommended
Linear relationship, normal dataPearson
Outliers presentSpearman
Ordinal dataSpearman or Kendall
Many tiesKendall
Nonlinear relationshipDistance Correlation
Rater agreementICC

🍪 Cookie Settings