Correlation coefficients: Pearson, Kendal, Spearmann

Hi, I need some coding for the computation of Pearson, Kendal and Spearmann coefficients in GAUSS

1 Answer



The Pearson correlation can be computed using the GAUSS procedure corrxs. This procedure takes a single matrix and computes the observed correlation matrix. Consider this example, using the dataset skincancer2.xlsx:

// Load data
data = loadd("skincancer2.xlsx");

// Check correlations
print "Pearson's correlation matrix:";

The results read:

Pearson's correlation matrix:

 1.000 -0.825
-0.825  1.000 

To calculate Spearman's Rank Correlation, or $\rho$, I have created the GAUSS procedure spearman for you to use:

// Load data for Spearman's correlation
iq = {106, 86, 100, 101, 99, 103, 97, 113, 112, 110};
tv = {7, 0, 27, 50, 28, 29, 20, 12, 6, 17};

tmp = spearmans(iq, tv);
print "Spearmans rank correlation:" tmp;

proc (1) = spearmans(xi, yi);
    local sorted_xi, rank_xi, rank_yi, d_i, d_i2;

    sorted_xi = sortc(xi~yi, 1);

    // Create rank according to xi
    rank_xi = seqa(1, 1, rows(xi));

    // Create rank according to yi
    rank_yi = sortind(sorted_xi[.,2]);

    // Create difference between ranks
    d_i = rank_xi - rank_yi;

    // Square the difference
    d_i2 = d_i.^2;

    retp(1 - (6*sumc(d_i2)/(rows(iq)*(rows(iq)^2-1))));

At this time, there is not a GAUSS procedure for computing the Kendall Rank Correlation. However, it is in progress and I will update this thread when one becomes available.



Your Answer

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy | Sitemap