Calculates the correlation coefficient between two variables given in two vectors of any size with one dimension applying the following equation:
Where:
z = correlation(x,y)
Where:
x
and y
= vectors of rank 1 with real numbers.
See this example to use an array of
rank larger than 1.z
= real number of the same kind as x
and y
with the correlation coefficient of x
and y
.The following program calculates the correlation coefficient between two variables:
PROGRAM correlationExample
USE FU_Statistics, ONLY: correlation
IMPLICIT NONE
REAL, DIMENSION(5) :: x = [1., 2., 3., 4., 5.]
REAL, DIMENSION(5) :: y = [6., 7., 8., 9., 10.]
WRITE(*,*) correlation(x, y)
END PROGRAM correlationExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in), | DIMENSION(:) | :: | x |
Vector of real numbers with the values of the first variable. It can have any size and it must have one dimension. |
|
real(kind=sp), | intent(in), | DIMENSION(:) | :: | y |
Vector of real numbers with the values of the second variable. It can have any size and it must have one dimension. |
Real number with the population covariance between both variables.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in), | DIMENSION(:) | :: | x |
Vector of real numbers with the values of the first variable. It can have any size and it must have one dimension. |
|
real(kind=dp), | intent(in), | DIMENSION(:) | :: | y |
Vector of real numbers with the values of the second variable. It can have any size and it must have one dimension. |
Real number with the population covariance between both variables.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=qp), | intent(in), | DIMENSION(:) | :: | x |
Vector of real numbers with the values of the first variable. It can have any size and it must have one dimension. |
|
real(kind=qp), | intent(in), | DIMENSION(:) | :: | y |
Vector of real numbers with the values of the second variable. It can have any size and it must have one dimension. |
Real number with the population covariance between both variables.