docs-v2/content/flux/v0.x/stdlib/universe/covariance.md

2.2 KiB

title description menu weight flux/v0.x/tags introduced
covariance() function `covariance()` computes the covariance between two columns.
flux_0_x_ref
name parent identifier
covariance universe universe/covariance
101
transformations
aggregates
0.7.0

covariance() computes the covariance between two columns.

Function type signature
(<-tables: stream[A], columns: [string], ?pearsonr: bool, ?valueDst: string) => stream[B] where A: Record, B: Record

{{% caption %}}For more information, see Function type signatures.{{% /caption %}}

Parameters

columns

({{< req >}}) List of two columns to operate on.

pearsonr

Normalize results to the Pearson R coefficient. Default is false.

valueDst

Column to store the result in. Default is _value.

tables

Input data. Default is piped-forward data (<-).

Examples

Calculate the covariance between two columns

data
    |> covariance(columns: ["x", "y"])

{{< expand-wrapper >}} {{% expand "View example input and ouput" %}}

Input data

_time x y
2021-01-01T00:00:00Z 0 0
2021-01-01T00:00:12Z 1 0.5
2021-01-01T00:00:24Z 4 8
2021-01-01T00:00:36Z 9 40.5
2021-01-01T00:00:48Z 16 128

Output data

_value
345.75

{{% /expand %}} {{< /expand-wrapper >}}