Skip to content
Nearest-neighbour correlation for non-linear relationships
MATLAB
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
nncorr_sims.m
teg_nncorr.m

README.md

nncorr

Nonlinear neighbourhood correlation.

This is a version of a non-linear correlation between variables X and Y that tests the correlation between the Y-scores of pairs of points that are neigbours on the X-axes. This can, e.g., detect U-curves or sinusoidal patterns in scatterplots. The trade-off is that it's less powerful at detecting linear relationships than a standard Peason's correlation.

In Matlab-code:

function [r, p] = teg_nncorr(x, y)

[x, si] = sort(x);
y = y(si);
y1_y2 = [];
for index1 = 1:2:(length(x) - 1)
    index2 = index1 + 1;
    y1 = y(index1);
    y2 = y(index2);
    y1_y2 = [y1_y2; y1 y2];
end
[r, p] = corr(y1_y2(:, 1), y1_y2(:, 2));

Please cite as: Thomas Edward Gladwin. (2020, March 13). thomasgladwin/nncorr: Initial release (Version v1). Zenodo. http://doi.org/10.5281/zenodo.3710404

DOI

You can’t perform that action at this time.