Header menu logo FSharp.Stats

Seq Module

Contains correlation functions optimized for sequences

Functions and values

Function or value Description

Seq.bicor seq1 seq2

Full Usage: Seq.bicor seq1 seq2

Parameters:
    seq1 : float seq -
    seq2 : float seq -

Returns: float

Biweighted Midcorrelation. This is a median based correlation measure which is more robust against outliers.

seq1 : float seq

seq2 : float seq

Returns: float

Example

Seq.bicorBy f seq

Full Usage: Seq.bicorBy f seq

Parameters:
    f : 'T -> float * float - A function applied to transform each element of the sequence into a tuple of paired observations.
    seq : 'T seq - The input sequence.

Returns: float The Biweighted Midcorrelation.
Modifiers: inline
Type parameters: 'T

Calculates the bicor correlation of two samples. The two samples are built by applying the given function to each element of the sequence. The function should transform each sequence element into a tuple of paired observations from the two samples. The correlation will be calculated between the paired observations.

f : 'T -> float * float

A function applied to transform each element of the sequence into a tuple of paired observations.

seq : 'T seq

The input sequence.

Returns: float

The Biweighted Midcorrelation.

Example

 // To get the correlation between A and B observations:
 let ab = [ {| A = 32.1; B = 1.2 |}
            {| A = 3.1; B = 0.4 |}
            {| A = 2.932; B = 3.85 |} ]
 
 ab |> Seq.bicorBy (fun x -> x.A, x.B) // evaluates to -0.9303913046
val ab: {| A: float; B: float |} list
anonymous record field A: float
anonymous record field B: float
module Seq from Microsoft.FSharp.Collections

Seq.bicorOfPairs seq

Full Usage: Seq.bicorOfPairs seq

Parameters:
    seq : (float * float) seq - The input sequence.

Returns: float The Biweighted Midcorrelation.
Modifiers: inline

Calculates the Biweighted Midcorrelation of two samples given as a sequence of paired values. This is a median based correlation measure which is more robust against outliers.

seq : (float * float) seq

The input sequence.

Returns: float

The Biweighted Midcorrelation.

Example

 
 // Consider a sequence of paired x and y values:
 // [(x1, y1); (x2, y2); (x3, y3); (x4, y4); ... ]
 let xy = [(32.1, 1.2); (3.1, 0.4); (2.932, 3.85)]
 
 // To get the correlation between x and y:
 xy |> Seq.bicorOfPairs // evaluates to -0.9303913046
val xy: (float * float) list
module Seq from Microsoft.FSharp.Collections

Seq.kendall seq1 seq2

Full Usage: Seq.kendall seq1 seq2

Parameters:
    seq1 : 'a seq - The first sequence of observations.
    seq2 : 'b seq - The second sequence of observations.

Returns: float Kendall Tau-b rank correlation coefficient of seq1 and seq2

Kendall Correlation Coefficient

This is an alias to kendallTauB. Computes Kendall Tau-b rank correlation coefficient between two sequences of observations. Tau-b is used to adjust for ties. tau_b = (n_c - n_d) / sqrt((n_0 - n_1) * (n_0 - n_2)), where

  • n_c: Number of concordant pairs.
  • n_d: Number of discordant pairs.
  • n_0: n*(n-1)/2 where n is the number of observations.
  • n_1: sum_i(t_i(t_i-1)/2) where t_i is the number of pairs of observations with the same x value.
  • n_2: sum_i(u_i(u_i-1)/2) where u_i is the number of pairs of observations with the same y value.

seq1 : 'a seq

The first sequence of observations.

seq2 : 'b seq

The second sequence of observations.

Returns: float

Kendall Tau-b rank correlation coefficient of seq1 and seq2

Example

 let x = [5.05;6.75;3.21;2.66]
 let y = [1.65;26.5;-0.64;6.95]

 Seq.kendall x y // evaluates to 0.3333333333
val x: float list
val y: float list
module Seq from Microsoft.FSharp.Collections

Seq.kendallBy f seq

Full Usage: Seq.kendallBy f seq

Parameters:
    f : 'T -> 'a * 'a - A function applied to transform each element of the sequence into a tuple of paired observations.
    seq : 'T seq - The input sequence.

Returns: float The kendall correlation coefficient.
Modifiers: inline
Type parameters: 'T, 'a

Calculates the kendall correlation of two samples. The two samples are built by applying the given function to each element of the sequence. The function should transform each sequence element into a tuple of paired observations from the two samples. The correlation will be calculated between the paired observations.

f : 'T -> 'a * 'a

A function applied to transform each element of the sequence into a tuple of paired observations.

seq : 'T seq

The input sequence.

Returns: float

The kendall correlation coefficient.

Example

 // To get the correlation between A and B observations:
 let ab = [ {| A = -0.5; B = -0.3 |}
            {| A = -0.4; B = -0.25 |}
            {| A = 0.; B = -0.1 |}
            {| A = 0.7; B = -0.46 |}
            {| A = 0.65; B = 0.103 |}
            {| A = 0.9649; B = 0.409 |} ]
 
 ab |> Seq.kendallBy (fun x -> x.A, x.B) // evaluates to 0.4666666667
val ab: {| A: float; B: float |} list
anonymous record field A: float
anonymous record field B: float
module Seq from Microsoft.FSharp.Collections

Seq.kendallOfPairs seq

Full Usage: Seq.kendallOfPairs seq

Parameters:
    seq : ('T * 'T) seq - The input sequence.

Returns: float The kendall correlation coefficient.
Modifiers: inline
Type parameters: 'T

Calculates the kendall correlation coefficient of two samples given as a sequence of paired values.

seq : ('T * 'T) seq

The input sequence.

Returns: float

The kendall correlation coefficient.

Example

 
 // Consider a sequence of paired x and y values:
 // [(x1, y1); (x2, y2); (x3, y3); (x4, y4); ... ]
 let xy = [(-0.5, -0.3); (-0.4, -0.25); (0., -0.1); (0.7, -0.46); (0.65, 0.103); (0.9649, 0.409)] 
 
 // To get the correlation between x and y:
 xy |> Seq.kendallOfPairs // evaluates to 0.4666666667
val xy: (float * float) list
module Seq from Microsoft.FSharp.Collections

Seq.kendallTauA seq1 seq2

Full Usage: Seq.kendallTauA seq1 seq2

Parameters:
    seq1 : 'a seq - The first sequence of observations.
    seq2 : 'b seq - The second sequence of observations.

Returns: float Kendall Tau-a rank correlation coefficient of setA and setB

Kendall Correlation Coefficient

Computes Kendall Tau-a rank correlation coefficient between two sequences of observations. No adjustment is made for ties. tau_a = (n_c - n_d) / n_0, where

  • n_c: Number of concordant pairs.
  • n_d: Number of discordant pairs.
  • n_0: n*(n-1)/2 where n is the number of observations.

seq1 : 'a seq

The first sequence of observations.

seq2 : 'b seq

The second sequence of observations.

Returns: float

Kendall Tau-a rank correlation coefficient of setA and setB

Example

 let x = [5.05;6.75;3.21;2.66]
 let y = [1.65;26.5;-0.64;6.95]

 Seq.kendallTauA x y // evaluates to 0.3333333333
val x: float list
val y: float list
module Seq from Microsoft.FSharp.Collections

Seq.kendallTauB seq1 seq2

Full Usage: Seq.kendallTauB seq1 seq2

Parameters:
    seq1 : 'a seq - The first sequence of observations.
    seq2 : 'b seq - The second sequence of observations.

Returns: float Kendall Tau-b rank correlation coefficient of seq1 and seq2

Kendall Correlation Coefficient

Computes Kendall Tau-b rank correlation coefficient between two sequences of observations. Tau-b is used to adjust for ties. tau_b = (n_c - n_d) / sqrt((n_0 - n_1) * (n_0 - n_2)), where

  • n_c: Number of concordant pairs.
  • n_d: Number of discordant pairs.
  • n_0: n*(n-1)/2 where n is the number of observations.
  • n_1: sum_i(t_i(t_i-1)/2) where t_i is the number of pairs of observations with the same x value.
  • n_2: sum_i(u_i(u_i-1)/2) where u_i is the number of pairs of observations with the same y value.

seq1 : 'a seq

The first sequence of observations.

seq2 : 'b seq

The second sequence of observations.

Returns: float

Kendall Tau-b rank correlation coefficient of seq1 and seq2

Example

 let x = [5.05;6.75;3.21;2.66]
 let y = [1.65;26.5;-0.64;6.95]

 Seq.kendallTauB x y // evaluates to 0.3333333333
val x: float list
val y: float list
module Seq from Microsoft.FSharp.Collections

Seq.kendallTauC seq1 seq2

Full Usage: Seq.kendallTauC seq1 seq2

Parameters:
    seq1 : 'a seq - The first sequence of observations.
    seq2 : 'b seq - The second sequence of observations.

Returns: float Kendall Tau-c rank correlation coefficient of seq1 and seq2

Kendall Correlation Coefficient

Computes Kendall Tau-c rank correlation coefficient between two sequences of observations. Tau-c is used to adjust for ties which is preferred to Tau-b when x and y have a different number of possible values. tau_c = 2(n_c - n_d) / (n^2 * (m-1)/m), where

  • n_c: Number of concordant pairs.
  • n_d: Number of discordant pairs.
  • n: The number of observations.
  • m: The lesser of the distinct x count and distinct y count.

seq1 : 'a seq

The first sequence of observations.

seq2 : 'b seq

The second sequence of observations.

Returns: float

Kendall Tau-c rank correlation coefficient of seq1 and seq2

Example

 let x = [1;1;1;2;2;2;3;3;3]
 let y = [2;2;4;4;6;6;8;8;10]

 Seq.kendallTauA x y // evaluates to 0.7222222222
 Seq.kendallTauB x y // evaluates to 0.8845379627
 Seq.kendallTauC x y // evaluates to 0.962962963
val x: int list
val y: int list
module Seq from Microsoft.FSharp.Collections

Seq.pearson seq1 seq2

Full Usage: Seq.pearson seq1 seq2

Parameters:
    seq1 : ^T seq -
    seq2 : ^T seq -

Returns: float
Modifiers: inline
Type parameters: ^T

Calculates the pearson correlation of two samples. Homoscedasticity must be assumed.

seq1 : ^T seq

seq2 : ^T seq

Returns: float

Example

Seq.pearsonBy f seq

Full Usage: Seq.pearsonBy f seq

Parameters:
    f : 'T -> ^a * ^a - A function applied to transform each element of the sequence into a tuple of paired observations.
    seq : 'T seq - The input sequence.

Returns: float The pearson correlation.
Modifiers: inline
Type parameters: 'T, ^a

Calculates the pearson correlation of two samples. The two samples are built by applying the given function to each element of the sequence. The function should transform each sequence element into a tuple of paired observations from the two samples. The correlation will be calculated between the paired observations.

f : 'T -> ^a * ^a

A function applied to transform each element of the sequence into a tuple of paired observations.

seq : 'T seq

The input sequence.

Returns: float

The pearson correlation.

Example

 // To get the correlation between A and B observations:
 let ab = [ {| A = 312.7; B = 315.5 |}
            {| A = 104.2; B = 101.3 |}
            {| A = 104.; B = 108. |}
            {| A = 34.7; B = 32.2 |} ]
 
 ab |> Seq.pearsonBy (fun x -> x.A, x.B) // evaluates to 0.9997053729
val ab: {| A: float; B: float |} list
anonymous record field A: float
anonymous record field B: float
module Seq from Microsoft.FSharp.Collections

Seq.pearsonOfPairs seq

Full Usage: Seq.pearsonOfPairs seq

Parameters:
    seq : (^T * ^T) seq - The input sequence.

Returns: float The pearson correlation.
Modifiers: inline
Type parameters: ^T

Calculates the pearson correlation of two samples given as a sequence of paired values. Homoscedasticity must be assumed.

seq : (^T * ^T) seq

The input sequence.

Returns: float

The pearson correlation.

Example

 
 // Consider a sequence of paired x and y values:
 // [(x1, y1); (x2, y2); (x3, y3); (x4, y4); ... ]
 let xy = [(312.7, 315.5); (104.2, 101.3); (104.0, 108.0); (34.7, 32.2)]
 
 // To get the correlation between x and y:
 xy |> Seq.pearsonOfPairs // evaluates to 0.9997053729
val xy: (float * float) list
module Seq from Microsoft.FSharp.Collections

Seq.pearsonWeighted seq1 seq2 weights

Full Usage: Seq.pearsonWeighted seq1 seq2 weights

Parameters:
    seq1 : ^T seq -
    seq2 : ^T seq -
    weights : ^T seq -

Returns: float
Modifiers: inline
Type parameters: ^T, ^a

weighted pearson correlation (http://sci.tech-archive.net/Archive/sci.stat.math/2006-02/msg00171.html)

seq1 : ^T seq

seq2 : ^T seq

weights : ^T seq

Returns: float

Example

Seq.pearsonWeightedBy f seq

Full Usage: Seq.pearsonWeightedBy f seq

Parameters:
    f : 'T -> ^a * ^a * ^a - A function applied to transform each element of the sequence into a tuple of triples representing the two samples and the weight. If the two samples are x and y then the elements of the sequence should be triples of x * y * weight
    seq : 'T seq - The input sequence.

Returns: float The weighted pearson correlation.
Modifiers: inline
Type parameters: 'T, ^a, ^b

Calculates the weighted pearson correlation of two samples after applying the given function to each element of the sequence.

f : 'T -> ^a * ^a * ^a

A function applied to transform each element of the sequence into a tuple of triples representing the two samples and the weight. If the two samples are x and y then the elements of the sequence should be triples of x * y * weight

seq : 'T seq

The input sequence.

Returns: float

The weighted pearson correlation.

Example

 // To get the correlation between A and B observations weighted by W:
 let abw = [ {| A = 1.1; B = 1.2; W = 0.2 |}
             {| A = 1.1; B = 0.9; W = 0.3 |}
             {| A = 1.2; B = 0.08; W = 0.5 |} ] 
 
 abw |> pearsonWeightedBy (fun x -> x.A, x.B, x.W)
 // evaluates to -0.9764158959
val abw: {| A: float; B: float; W: float |} list
anonymous record field A: float
anonymous record field B: float
anonymous record field W: float

Seq.pearsonWeightedOfTriples seq

Full Usage: Seq.pearsonWeightedOfTriples seq

Parameters:
    seq : (^T * ^T * ^T) seq - The input sequence.

Returns: float The weighted pearson correlation.
Modifiers: inline
Type parameters: ^T, ^a

Calculates the weighted pearson correlation of two samples. If the two samples are x and y then the elements of the input sequence should be triples of x * y * weight.

seq : (^T * ^T * ^T) seq

The input sequence.

Returns: float

The weighted pearson correlation.

Example

 // Consider a sequence of triples with x, y and w values:
 // [(x1, y1, w1); (x2, y2, w2); (x3, y3, w3); (x4, y4, w4); ... ]
 let xyw = [(1.1, 1.2, 0.2); (1.1, 0.9, 0.3); (1.2, 0.08, 0.5)] 
 
 // To get the correlation between x and y weighted by w :
 xyw |> Seq.pearsonWeightedOfTriples // evaluates to -0.9764158959
val xyw: (float * float * float) list
module Seq from Microsoft.FSharp.Collections

Seq.spearman seq1 seq2

Full Usage: Seq.spearman seq1 seq2

Parameters:
    seq1 : ^T seq
    seq2 : ^T seq

Returns: float The spearman correlation.
Modifiers: inline
Type parameters: ^T

Spearman Correlation (with ranks) Items that are tied are each allocated the average of the ranks that they would have had had they been distinguishable. Reference: Williams R.B.G. (1986) Spearman’s and Kendall’s Coefficients of Rank Correlation. Intermediate Statistics for Geographers and Earth Scientists, p453, https://doi.org/10.1007/978-1-349-06813-5_6

seq1 : ^T seq
seq2 : ^T seq
Returns: float

The spearman correlation.

Example

 let x = [5.05;6.75;3.21;2.66]
 let y = [1.65;2.64;2.64;6.95]
 
 // To get the correlation between x and y:
 Seq.spearman x y // evaluates to -0.632455532
val x: float list
val y: float list
module Seq from Microsoft.FSharp.Collections

Seq.spearmanBy f seq

Full Usage: Seq.spearmanBy f seq

Parameters:
    f : 'T -> ^a * ^a - A function applied to transform each element of the sequence into a tuple of paired observations.
    seq : 'T seq - The input sequence.

Returns: float The spearman correlation.
Modifiers: inline
Type parameters: 'T, ^a

Calculates the spearman correlation of two samples. The two samples are built by applying the given function to each element of the sequence. The function should transform each sequence element into a tuple of paired observations from the two samples. The correlation will be calculated between the paired observations.

f : 'T -> ^a * ^a

A function applied to transform each element of the sequence into a tuple of paired observations.

seq : 'T seq

The input sequence.

Returns: float

The spearman correlation.

Example

 // To get the correlation between A and B observations:
 let ab = [ {| A = 1.1; B = 1.2 |}
            {| A = 1.1; B = 0.9 |}
            {| A = 2.0; B = 3.85 |} ] 
 
 ab |> Seq.spearmanBy (fun x -> x.A, x.B) // evaluates to 0.5
val ab: {| A: float; B: float |} list
anonymous record field A: float
anonymous record field B: float
module Seq from Microsoft.FSharp.Collections

Seq.spearmanOfPairs seq

Full Usage: Seq.spearmanOfPairs seq

Parameters:
    seq : (^T * ^T) seq - The input sequence.

Returns: float The spearman correlation.
Modifiers: inline
Type parameters: ^T

Calculates the spearman correlation (with ranks) of two samples given as a sequence of paired values.

seq : (^T * ^T) seq

The input sequence.

Returns: float

The spearman correlation.

Example

 
 // Consider a sequence of paired x and y values:
 // [(x1, y1); (x2, y2); (x3, y3); (x4, y4); ... ]
 let xy = [(1.1, 1.2); (1.1, 0.9); (2.0, 3.85)]
 
 // To get the correlation between x and y:
 xy |> Seq.spearmanOfPairs // evaluates to 0.5
val xy: (float * float) list
module Seq from Microsoft.FSharp.Collections

Type something to start searching.