<< nisp_buildlhs Support nisp_cov >>

NISP >> NISP > Support > nisp_corrcoef

nisp_corrcoef

Returns the linear correlation coefficient of x and y.

Calling Sequence

r = nisp_corrcoef ( x , y )

Parameters

x:

a n-by-1 or 1-by-n matrix of doubles

y:

a n-by-1 or 1-by-n matrix of doubles

r:

a 1-by-1 matrix of doubles, the linear correlation coefficient.

Description

Returns the linear correlation coefficient of x and y. This is sometimes called Pearson's product-moment coefficient.

It is defined by

Examples

// "Introduction to probability and statistics for
// engineers and scientists."
// Sheldon Ross
// Chapter 2 Descriptive statistics
// Example 2.6a
x = [24.2;22.7;30.5;28.6;25.5;32;28.6;26.5;25.3;26;24.4;24.8;20.6;..
25.1;21.4;23.7;23.9;25.2;27.4;28.3;28.8;26.6];
y = [25;31;36;33;19;24;27;25;16;14;22;23;20;25;25;23;27;30;33;32;35;24];
expected = 0.4189
r = nisp_corrcoef ( x , y )
// Draw the scatter plot
scf();
plot(x,y,"bo")

// "Introduction to probability and statistics for
// engineers and scientists."
// Sheldon Ross
// Chapter 2 Descriptive statistics
// Example 2.6b
x = [12 16 13 18 19 12 18 19 12 14];
y = [73 67 74 63 73 84 60 62 76 71];
r = nisp_corrcoef ( x , y )
expected = -0.7638

// For properly chosen data, the linear correlation
// coefficient can be close to zero.
n = 1000;
x = linspace(-%pi/2,3*%pi/2,n);
y = sin(x)+grand(1,n,"nor",0,0.5);
r = nisp_corrcoef ( x , y )
// This does not imply that there is no dependency
// between the variables
scf();
plot(x,y,"bo")

Authors

Bibliography

"Introduction to probability and statistics for engineers and scientists.", Sheldon Ross

http://en.wikipedia.org/wiki/Correlation_and_dependence

<< nisp_buildlhs Support nisp_cov >>