correlation Interface

public interface correlation

Calculates the correlation coefficient between two variables given in two vectors of any size with one dimension applying the following equation:

Where:

  • and are vectors with real numbers.
  • is how many numbers are included in and .

Syntax

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.

Example

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

Contents


Module Procedures

private pure function correlation_sp(x, y) result(res)

Arguments

Type IntentOptional 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.

Return Value real(kind=sp)

Real number with the population covariance between both variables.

private pure function correlation_dp(x, y) result(res)

Arguments

Type IntentOptional 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.

Return Value real(kind=dp)

Real number with the population covariance between both variables.

private pure function correlation_qp(x, y) result(res)

Arguments

Type IntentOptional 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.

Return Value real(kind=qp)

Real number with the population covariance between both variables.