linreg Interface

public interface linreg

Performs linear regression between two sets of values, obtaining parameters and of the following equation.

Where:

  • and are vectors with real numbers.
  • and are the regression coefficients.

Parameter is also calculated to measure the goodness of fit.

Syntax

CALL linreg(x,y,a,b,R2)

Where:

  • x and y = vectors of rank 1 with real numbers. See this example to use an array of rank larger than 1.
  • a, b = regression coefficients calculated by the subroutine.
  • R2 = the determination coefficient to measure the goodness of fit, calculated by the subroutine.

Example

The following program performs a linear regression of two variables:

 PROGRAM linregExample
    USE FU_Statistics, ONLY: linreg
    IMPLICIT NONE
    REAL, DIMENSION(5) :: x = [1., 2., 3., 4., 5.]
    REAL, DIMENSION(5) :: y = [3., 4., 5., 6., 7.]
    REAL :: a, b, R2
    CALL linreg(x, y, a, b, R2)
    WRITE(*,*) a, b, R2
 END PROGRAM linregExample

Contents


Module Procedures

private pure subroutine linreg_sp(x, y, a, b, R2)

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.

real(kind=sp), intent(out) :: a

Regression coefficient.

real(kind=sp), intent(out) :: b

Regression coefficient.

real(kind=sp), intent(out) :: R2

Determination coefficient.

private pure subroutine linreg_dp(x, y, a, b, R2)

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.

real(kind=dp), intent(out) :: a

Regression coefficient.

real(kind=dp), intent(out) :: b

Regression coefficient.

real(kind=dp), intent(out) :: R2

Determination coefficient.

private pure subroutine linreg_qp(x, y, a, b, R2)

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.

real(kind=qp), intent(out) :: a

Regression coefficient.

real(kind=qp), intent(out) :: b

Regression coefficient.

real(kind=qp), intent(out) :: R2

Determination coefficient.