Hi, I need some coding for the computation of Pearson, Kendal and Spearmann coefficients in GAUSS
1 Answer
0
Hi,
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:"; corrxs(data[.,2]~data[.,3]);
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)))); endp;
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
1 Answer
Hi,
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:"; corrxs(data[.,2]~data[.,3]);
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)))); endp;
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.