STS: Sample Statistics

Overview

This is the API documentation for all sample statistics procedures.


Mean

fsml_mean

Computes arithmetic mean. where is the size of (or number of observations in) vector x, are individual elements in x, and is the arithmetic mean of x.

Description

Syntax

result = fsml_mean(x)

Parameters

x: A rank-1 array of type real.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x.


Variance

fsml_var

Description

Computes the population or sample variance (depending on passed arguments). where is the size of (or number of observations in) vector x, are individual elements in x, (ddof) is a degrees of freedom adjustment (ddof = 0.0 for population variance, ddof = 1.0 for sample variance), and is the arithmetic mean of x.

Syntax

result = fsml_var(x [,ddof])

Parameters

x: A rank-1 array of type real.

ddof: An optional argument and scalar of type real. If passed, it must be either 0.0 or 1.0. It will default to 0.0 if not passed.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x.


Standard Deviation

fsml_std

Description

Computes the population or sample standard deviation (depending on passed arguments). where is the variance of vector x, is the size of (or number of observations in) vector x, are individual elements in x, and (ddof) is a degrees of freedom adjustment (ddof = 0.0 for population variance, ddof = 1.0 for sample variance).

Syntax

result = fsml_std(x [,ddof])

Parameters

x: A rank-1 array of type real.

ddof: An optional argument and scalar of type real. If passed, it must be either 0.0 or 1.0. It will default to 0.0 if not passed.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x.


Covariance

fsml_cov

Description

Computes the population or sample covariance (depending on passed arguments). where is the size of (or number of observations in) vectors x and y, and are individual elements in x and y, (ddof) is a degrees of freedom adjustment (ddof = 0.0 for population variance, ddof = 1.0 for sample variance), and and are the arithmetic means of x and y.

Vectors x and y must be the same size.

Syntax

result = fsml_cov(x, y [,ddof])

Parameters

x: A rank-1 array of type real. It must be the same size as y.

y: A rank-1 array of type real. It must be the same size as x.

ddof: An optional argument and scalar of type real. If passed, it must be either 0.0 or 1.0. It will default to 0.0 if not passed.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x and y.


Linear Trend

fsml_trend

Description

Computes regression coefficient/trend. where is the slope of the regression line (linear trend), is the covariance of x and y, and is the variance of x.

Vectors x and y must be the same size.

Syntax

result = fsml_trend(x, y)

Parameters

x: A rank-1 array of type real. It must be the same size as y.

y: A rank-1 array of type real. It must be the same size as x.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x and y.


Pearson Correlation Coefficient

fsml_pcc

Description

Computes Pearson correlation coefficient (PCC). where is the Pearson correlation coefficient for vectors x and y, is the covariance of x and y, and and are the standard deviations of x and y.

Vectors x and y must be the same size.

Syntax

result = fsml_pcc(x, y)

Parameters

x: A rank-1 array of type real. It must be the same size as y.

y: A rank-1 array of type real. It must be the same size as x.

Invalid argument values will result in the return of a sentinel value.

Returns

The result is a scalar and the same type as x and y.


Examples

program example_sts

! |--------------------------------------------------------------------|
! | fsml - fortran statistics and machine learning library             |
! |                                                                    |
! | about                                                              |
! | -----                                                              |
! | Examples for basic statistics (sts module).                        |
! |                                                                    |
! | license : MIT                                                      |
! | author  : Sebastian G. Mutz (sebastian@sebastianmutz.com)          |
! |--------------------------------------------------------------------|

  use :: fsml
  use :: fsml_ini ! import wp; alternatively: iso_fortran_env, wp => real64

  implicit none

! ==== Description
!! The programme demonstrates the use of several statistics procedures based on
!! the same few data vectors.

! ==== Declarations
  integer(i4), parameter :: n1 = 10
  real(wp)   , parameter :: x1(n1) =        &
                                  [1.10_wp, &
                                   1.22_wp, &
                                   0.11_wp, &
                                   2.31_wp, &
                                   1.72_wp, &
                                   2.21_wp, &
                                   3.10_wp, &
                                   2.27_wp, &
                                   1.21_wp, &
                                   1.01_wp]
  real(wp)   , parameter :: x2(n1) =        &
                                  [2.10_wp, &
                                   1.10_wp, &
                                   0.23_wp, &
                                   1.25_wp, &
                                   1.95_wp, &
                                   1.52_wp, &
                                   1.00_wp, &
                                   1.05_wp, &
                                   2.32_wp, &
                                   1.40_wp]

! ==== Instructions

  ! mean of vector x1
  print*, "mean (x1): ", fsml_mean(x1)
  ! 1.6260000000000001

  ! variance of vector x1
  print*, "variance (x1): ", fsml_var(x1)
  ! 0.66974399999999989

  ! sample variance of vector x1
  print*, "sample variance (x1): ", fsml_var(x1, ddof=1.0_wp)
  ! 0.74415999999999993

  ! standard deviation of vector x1
  print*, "standard deviation (x1): ", fsml_std(x1)
  ! 0.81837888535812064

  ! sample standard deviation of vector x1
  print*, "sample standard deviation (x1): ", fsml_std(x1, ddof=1.0_wp)
  ! 0.86264708890716135

  ! covariance of x1 and x2
  print*, "covariance (x1, x2): ", fsml_cov(x1, x2)
  ! 3.4878000000000006E-002

  ! sample covariance of x1 and x2
  print*, "sample covariance (x1, x2): ", fsml_cov(x1, x2, ddof=1.0_wp)
  ! 3.8753333333333341E-002

  ! linear regression slope for x1 and x2
  print*, "trend (x1, x2): ", fsml_trend(x1, x2)
  ! 5.2076614348168869E-002

  ! Pearson correlation coefficient for x1 and x2
  print*, "correlation (x1, x2): ", fsml_pcc(x1, x2)
  ! 7.2912607800353288E-002

end program example_sts