Back to Influxdb

covariance() function

content/flux/v0/stdlib/universe/covariance.md

latest1.9 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L192-L200 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

covariance() computes the covariance between two columns.

Function type signature
js
(<-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

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

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

Input data

_timexy
2021-01-01T00:00:00Z00
2021-01-01T00:00:12Z10.5
2021-01-01T00:00:24Z48
2021-01-01T00:00:36Z940.5
2021-01-01T00:00:48Z16128

Output data

_value
345.75

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