# `Scholar.Stats`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L1)

Statistical functions

All of the functions in this module are implemented as
numerical functions and can be JIT or AOT compiled with
any supported `Nx` compiler.

# `correlation_matrix`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L221)

Computes correlation matrix for sample inputs `x`.

The value on the position $Corr_{ij}$ in the $Corr$ matrix is calculated using the formula:
$$ Corr(X\_i, X\_j) = \frac{Cov(X\_i, X\_j)}{\sqrt{Cov(X\_i, X\_i)Cov(X\_j, X\_j)}} $$
Where:
  * $X_i$ is a $i$th row of input

  * $Cov(X\_i, X\_j)$ is covariance between features $X_i$ and $X_j$

Time complexity of correlation estimation is $O(N * K^2)$ where $N$ is the number of samples
and $K$ is the number of features.

## Example

    iex> Scholar.Stats.correlation_matrix(Nx.tensor([[3, 6, 5], [26, 75, 3], [23, 4, 1]]))
    #Nx.Tensor<
      f32[3][3]
      [
        [1.0, 0.580316960811615, -0.7997867465019226],
        [0.580316960811615, 1.0, 0.024736011400818825],
        [-0.7997867465019226, 0.024736011400818825, 1.0]
      ]
    >

    iex> Scholar.Stats.correlation_matrix(Nx.tensor([[3, 6], [2, 3], [7, 9], [5, 3]]))
    #Nx.Tensor<
      f32[2][2]
      [
        [1.0, 0.6673083305358887],
        [0.6673083305358887, 1.0]
      ]
    >

    iex> x = Nx.tensor([[3, 6, 5], [26, 75, 3], [23, 4, 1]])
    iex> means = Nx.mean(x, axes: [-2])
    iex> Scholar.Stats.correlation_matrix(x, means)
    #Nx.Tensor<
      f32[3][3]
      [
        [1.0, 0.580316960811615, -0.7997867465019226],
        [0.580316960811615, 1.0, 0.024736011400818825],
        [-0.7997867465019226, 0.024736011400818825, 1.0]
      ]
    >

# `correlation_matrix`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L228)

# `kurtosis`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L140)

Computes the kurtosis (Fisher or Pearson) of a dataset.

## Options

* `:axes` - Axes to calculate the operation. If set to `nil` then
  the operation is performed on the whole tensor. The default value is `[0]`.

* `:keep_axes` (`t:boolean/0`) - If set to true, the axes which are reduced are left. The default value is `false`.

* `:bias` (`t:boolean/0`) - If false, then the calculations are corrected for statistical bias. The default value is `true`.

* `:variant` - If :fisher then Fisher's definition is used, if :pearson then Pearson's definition is used. The default value is `:fisher`.

## Examples

    iex> x = Nx.tensor([[3, 5, 3], [2, 6, 1], [9, 3, 2], [1, 6, 8]])
    iex> Scholar.Stats.kurtosis(x)
    #Nx.Tensor<
      f32[3]
      [-0.7980852127075195, -1.0, -0.8394768238067627]
    >

# `moment`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L74)

Calculates the nth moment about the mean for a sample.

## Options

* `:axes` - Axes to calculate the operation. If set to `nil` then
  the operation is performed on the whole tensor. The default value is `[0]`.

* `:keep_axes` (`t:boolean/0`) - If set to true, the axes which are reduced are left. The default value is `false`.

## Examples

    iex> x = Nx.tensor([[3, 5, 3], [2, 6, 1], [9, 3, 2], [1, 6, 8]])
    iex> Scholar.Stats.moment(x, 2)
    #Nx.Tensor<
      f32[3]
      [9.6875, 1.5, 7.25]
    >

# `skew`
[🔗](https://github.com/elixir-nx/scholar/blob/main/lib/scholar/stats.ex#L104)

Computes the sample skewness of a data set.

## Options

* `:axes` - Axes to calculate the operation. If set to `nil` then
  the operation is performed on the whole tensor. The default value is `[0]`.

* `:keep_axes` (`t:boolean/0`) - If set to true, the axes which are reduced are left. The default value is `false`.

* `:bias` (`t:boolean/0`) - If false, then the calculations are corrected for statistical bias. The default value is `true`.

## Examples

    iex> x = Nx.tensor([[3, 5, 3], [2, 6, 1], [9, 3, 2], [1, 6, 8]])
    iex> Scholar.Stats.skew(x)
    #Nx.Tensor<
      f32[3]
      [0.9794093370437622, -0.8164965510368347, 0.9220733642578125]
    >

---

*Consult [api-reference.md](api-reference.md) for complete listing*
