gelman/summarize

This module defines functions that compute the summary statistics for a given dataset.

A summary statistic is a function that takes many data points and returns one single value that describes a property of the dataset.

Each function within this module takes as its first argument a dataset, which is a list of floats.

Every function within this module could potentially produce StatsError. For more information about the what each error represents, please refer to gelman/error

Values

pub fn generalized_mean(
  dataset: List(Float),
  p: Float,
) -> Result(Float, error.StatsError)

Computes the geometric mean in one pass, avoiding the memory overhead of materializing the intermediate list. This is also known as the Hoelder mean. When the power p is zero, we send the geometric mean, which is the limit of the generalized mean as it tends to zero.

pub fn geometric_mean(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the geometric mean in one pass. Since there is no list fusion in Gleam, this means that the geometric transformation is applied in a single fold, as opposed to |> map(transform) |> mean(), to avoid memory overhead of materializing the intermediate list.

pub fn harmonic_mean(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the geometric mean in one pass, avoiding the memory overhead of materializing the intermediate list.

pub fn interquartile_range(
  dataset: List(Float),
) -> Result(Float, error.StatsError)
pub fn kurtosis(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the kurtosis of a dataset in one pass, using sum, sum of squares, sum of cubes and sum of fourth powers.

Note: this is standard kurtosis, not Fisher kurtosis (also known as excess kurtosis). To compute excess kurtosis, subtract 3 from this result.

pub fn mean(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the mean of a dataset in one pass.

pub fn median(
  dataset: List(Float),
) -> Result(Float, error.StatsError)
pub fn median_absolute_deviation(
  dataset: List(Float),
) -> Result(Float, error.StatsError)
pub fn moment(
  dataset: List(Float),
  order n: Int,
) -> Result(Float, error.StatsError)
pub fn skewness(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the variance of a dataset in one pass, using sum, sum of squares and sum of cubes.

pub fn standard_deviation(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the standard deviation of a dataset in one pass. This is simply equal to the square root of the variance. That is the standard deviation without correction for degrees of freedom.

TODO: Implement standard deviation with correction for degrees of freedom

pub fn variance(
  dataset: List(Float),
) -> Result(Float, error.StatsError)

Computes the variance of a dataset in one pass, using sum and the sum of squares.

Search Document