The covariance of two random variables measures their connectedness; i.e., whether they tend to change with each other. If X and Y are two random variables, then the covariance is the expected value of (X−X)(Y−Ȳ), where X and Ȳ are the means of X and Y, respectively. The covariance command calculates covariances.
If the arguments consist of two lists and a matrix, to make it simpler to enter the data in a spreadsheet the lists X and Y and the matrix W can be combined into a single matrix, by augmenting W with the list Y on the top and the transpose of the list X on the left, with a filler in the upper left hand corner:
|
For this, you have to give covariance a second argument of -1.
Examples.
|
|
The linear correlation coefficient of two random variables is another way to measure their connectedness. Given random variables X and Y, their correlation is defined as cov(X,Y)/(σ(X)σ(Y)), cov(X,Y) is the covariance of X and Y, and σ(X) and σ(Y) are the standard deviations of X and Y, respectively.
The correlation command finds the correlation of two lists and take the same types of arguments as the covariance command.
If the arguments consist of two lists and a matrix, to make it simpler to enter the data in a spreadsheet the lists X and Y and the matrix W can be combined into a single matrix, by augmenting W with the list Y on the top and the transpose of the list X on the left, with a filler in the upper left hand corner:
|
For this, you have to give correlation a second argument of -1.
Example.
Input:
Output:
|
The covariance_correlation command will compute both the covariance and correlation simultaneously, and return a list with both values. This command takes the same type of arguments as the covariance and correlation commands.
If the arguments consist of two lists and a matrix, to make it simpler to enter the data in a spreadsheet the lists X and Y and the matrix W can be combined into a single matrix, by augmenting W with the list Y on the top and the transpose of the list X on the left, with a filler in the upper left hand corner:
|
For this, you have to give covariance_correlation a second argument of -1.
Example.
Input:
Output:
⎡ ⎢ ⎢ ⎢ ⎢ ⎣ |
| , |
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎦ |