Seq Module

Contains correlation functions optimized for sequences

Functions and values

Function or value Description

bicor seq1 seq2

Full Usage: bicor seq1 seq2

Parameters:
    seq1 : seq<float> -
    seq2 : seq<float> -

Returns: float

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

seq1 : seq<float>

seq2 : seq<float>

Returns: float

Example

bicorBy f seq

Full Usage: 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 : seq<'T> - The input sequence.

Returns: float The kendall correlation coefficient.
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 : seq<'T>

The input sequence.

Returns: float

The kendall correlation coefficient.

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

bicorOfPairs seq

Full Usage: bicorOfPairs seq

Parameters:
    seq : seq<float * float> - 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 : seq<float * float>

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

kendall setA setB

Full Usage: kendall setA setB

Parameters:
    setA : 'b[] -
    setB : 'c[] -

Returns: float

Kendall Correlation Coefficient

setA : 'b[]

setB : 'c[]

Returns: float

Example

kendallBy f seq

Full Usage: 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 : seq<'T> - The input sequence.

Returns: float The kendall correlation coefficient.
Modifiers: inline

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 : seq<'T>

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

kendallOfPairs seq

Full Usage: kendallOfPairs seq

Parameters:
    seq : seq<'T * 'T> - 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 : seq<'T * 'T>

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

pearson seq1 seq2

Full Usage: pearson seq1 seq2

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

Returns: float
Modifiers: inline
Type parameters: ^T

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

seq1 : seq<^T>

seq2 : seq<^T>

Returns: float

Example

pearsonBy f seq

Full Usage: 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 : seq<'T> - The input sequence.

Returns: float The pearson correlation.
Modifiers: inline

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 : seq<'T>

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

pearsonOfPairs seq

Full Usage: pearsonOfPairs seq

Parameters:
    seq : seq<^T * ^T> - 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 : seq<^T * ^T>

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

pearsonWeighted seq1 seq2 weights

Full Usage: pearsonWeighted seq1 seq2 weights

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

Returns: float
Modifiers: inline

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

seq1 : seq<^T>

seq2 : seq<^T>

weights : seq<^T>

Returns: float

Example

pearsonWeightedBy f seq

Full Usage: 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 : seq<'T> - The input sequence.

Returns: float The weighted pearson correlation.
Modifiers: inline

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 : seq<'T>

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

pearsonWeightedOfTriples seq

Full Usage: pearsonWeightedOfTriples seq

Parameters:
    seq : seq<^T * ^T * ^T> - The input sequence.

Returns: float The weighted pearson correlation.
Modifiers: inline

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 : seq<^T * ^T * ^T>

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

spearman seq1 seq2

Full Usage: spearman seq1 seq2

Parameters:
    seq1 : seq<^T>
    seq2 : seq<^T>

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 : seq<^T>
seq2 : seq<^T>
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

spearmanBy f seq

Full Usage: 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 : seq<'T> - The input sequence.

Returns: float The spearman correlation.
Modifiers: inline

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 : seq<'T>

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

spearmanOfPairs seq

Full Usage: spearmanOfPairs seq

Parameters:
    seq : seq<^T * ^T> - 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 : seq<^T * ^T>

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