Skip to content

Nearest-neighbour correlation for non-linear relationships

Notifications You must be signed in to change notification settings

thomasgladwin/nncorr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

nncorr

Nonlinear neighbourhood correlation.

Product of some idle musings about non-linear, very general measures of association, not sure whether it's any use for anything: This is a very simple 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 neighbours 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));

DOI

About

Nearest-neighbour correlation for non-linear relationships

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages