pcovariance Interface

public interface pcovariance

Calculates the population covariance 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 = pcovariance(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 population covariance of x and y.

Example

The following program calculates the population covariance between two variables:

 PROGRAM pcovarianceExample
    USE FU_Statistics, ONLY: pcovariance
    IMPLICIT NONE
    REAL, DIMENSION(5) :: x = [1., 2., 3., 4., 5.]
    REAL, DIMENSION(5) :: y = [6., 7., 8., 9., 10.]
    WRITE(*,*) pcovariance(x, y)
 END PROGRAM pcovarianceExample

Contents


Module Procedures

private pure function pcovariance_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 pcovariance_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 pcovariance_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.