math-php
Static Public Member Functions | List of all members
MathPHP\Statistics\Average Class Reference

Statistical averages. More...

Static Public Member Functions

static mean (array $numbers)
 Calculate the mean average of a list of numbers. More...
 
static weightedMean (array $numbers, array $weights)
 Calculate the weighted mean average of a list of numbers https://en.wikipedia.org/wiki/Weighted_arithmetic_mean. More...
 
static median (array $numbers)
 Calculate the median average of a list of numbers. More...
 
static kthSmallest (array $numbers, int $k)
 Return the kth smallest value in an array Uses a linear-time algorithm: O(n) time in worst case. More...
 
static mode (array $numbers)
 Calculate the mode average of a list of numbers If multiple modes (bimodal, trimodal, etc.), all modes will be returned. More...
 
static geometricMean (array $numbers)
 Geometric mean A type of mean which indicates the central tendency or typical value of a set of numbers by using the product of their values (as opposed to the arithmetic mean which uses their sum). More...
 
static harmonicMean (array $numbers)
 Harmonic mean (subcontrary mean) The harmonic mean can be expressed as the reciprocal of the arithmetic mean of the reciprocals. More...
 
static contraharmonicMean (array $numbers)
 Contraharmonic mean A function complementary to the harmonic mean. More...
 
static rootMeanSquare (array $numbers)
 Root mean square (quadratic mean) The square root of the arithmetic mean of the squares of a set of numbers. More...
 
static quadraticMean (array $numbers)
 Quadradic mean (root mean square) Convenience function for rootMeanSquare. More...
 
static trimean (array $numbers)
 Trimean (TM, or Tukey's trimean) A measure of a probability distribution's location defined as a weighted average of the distribution's median and its two quartiles. More...
 
static interquartileMean (array $numbers)
 Interquartile mean (IQM) A measure of central tendency based on the truncated mean of the interquartile range. More...
 
static iqm (array $numbers)
 IQM (Interquartile mean) Convenience function for interquartileMean. More...
 
static cubicMean (array $numbers)
 Cubic mean https://en.wikipedia.org/wiki/Cubic_mean


/ 1 n x cubic = ³/ - ∑ xᵢ³ √ n ⁱ⁼¹ More...

 
static truncatedMean (array $numbers, int $trim_percent)
 Truncated mean (trimmed mean) The mean after discarding given parts of a probability distribution or sample at the high and low end, and typically discarding an equal amount of both. More...
 
static lehmerMean (array $numbers, $p)
 Lehmer mean https://en.wikipedia.org/wiki/Lehmer_mean. More...
 
static generalizedMean (array $numbers, float $p)
 Generalized mean (power mean, Hölder mean) https://en.wikipedia.org/wiki/Generalized_mean. More...
 
static powerMean (array $numbers, float $p)
 Power mean (generalized mean) Convenience method for generalizedMean. More...
 
static simpleMovingAverage (array $numbers, int $n)
 Simple n-point moving average SMA The unweighted mean of the previous n data. More...
 
static cumulativeMovingAverage (array $numbers)
 Cumulative moving average (CMA) More...
 
static weightedMovingAverage (array $numbers, int $n, array $weights)
 Weighted n-point moving average (WMA) More...
 
static exponentialMovingAverage (array $numbers, int $n)
 Exponential moving average (EMA) More...
 
static arithmeticGeometricMean (float $x, float $y)
 Arithmetic-Geometric mean. More...
 
static agm (float $x, float $y)
 Convenience method for arithmeticGeometricMean. More...
 
static logarithmicMean (float $x, float $y)
 Logarithmic mean A function of two non-negative numbers which is equal to their difference divided by the logarithm of their quotient. More...
 
static heronianMean (float $A, float $B)
 Heronian mean https://en.wikipedia.org/wiki/Heronian_mean __ H = ⅓(A + √AB + B) More...
 
static identricMean (float $x, float $y)
 Identric mean https://en.wikipedia.org/wiki/Identric_mean


1 / xˣ I(x,y) = - ˣ⁻ʸ/ – ℯ √ yʸ More...

 
static describe (array $numbers)
 Get a report of all the averages over a list of numbers Includes mean, median mode, geometric mean, harmonic mean, quardratic mean. More...
 

Detailed Description

Statistical averages.

Member Function Documentation

◆ agm()

static MathPHP\Statistics\Average::agm ( float  $x,
float  $y 
)
static

Convenience method for arithmeticGeometricMean.

Parameters
float$x
float$y
Returns
float

◆ arithmeticGeometricMean()

static MathPHP\Statistics\Average::arithmeticGeometricMean ( float  $x,
float  $y 
)
static

Arithmetic-Geometric mean.

First, compute the arithmetic and geometric means of x and y, calling them a₁ and g₁ respectively. Then, use iteration, with a₁ taking the place of x and g₁ taking the place of y. Both a and g will converge to the same mean. https://en.wikipedia.org/wiki/Arithmetic%E2%80%93geometric_mean

x and y ≥ 0 If x or y = 0, then agm = 0 If x or y < 0, then NaN

Parameters
float$x
float$y
Returns
float

◆ contraharmonicMean()

static MathPHP\Statistics\Average::contraharmonicMean ( array  $numbers)
static

Contraharmonic mean A function complementary to the harmonic mean.

A special case of the Lehmer mean, L₂(x), where p = 2. https://en.wikipedia.org/wiki/Contraharmonic_mean

Parameters
array$numbers
Returns
float

◆ cubicMean()

static MathPHP\Statistics\Average::cubicMean ( array  $numbers)
static

Cubic mean https://en.wikipedia.org/wiki/Cubic_mean


/ 1 n x cubic = ³/ - ∑ xᵢ³ √ n ⁱ⁼¹

Parameters
array$numbers
Returns
float

◆ cumulativeMovingAverage()

static MathPHP\Statistics\Average::cumulativeMovingAverage ( array  $numbers)
static

Cumulative moving average (CMA)

Base case for initial average: x₀ CMA₀ = – 1

Standard case: xᵢ + (i * CMAᵢ₋₁) CMAᵢ = --------------— i + 1

Parameters
array$numbers
Returns
array of cumulative averages

◆ describe()

static MathPHP\Statistics\Average::describe ( array  $numbers)
static

Get a report of all the averages over a list of numbers Includes mean, median mode, geometric mean, harmonic mean, quardratic mean.

Parameters
array$numbers
Returns
array [ mean, median, mode, geometric_mean, harmonic_mean, contraharmonic_mean, quadratic_mean, trimean, iqm, cubic_mean ]
Exceptions
Exception

◆ exponentialMovingAverage()

static MathPHP\Statistics\Average::exponentialMovingAverage ( array  $numbers,
int  $n 
)
static

Exponential moving average (EMA)

The start of the EPA is seeded with the first data point. Then each day after that: EMAtoday = α⋅xtoday + (1-α)EMAyesterday

where α: coefficient that represents the degree of weighting decrease, a constant smoothing factor between 0 and 1.

Parameters
array$numbers
int$nLength of the EPA
Returns
array of exponential moving averages

◆ generalizedMean()

static MathPHP\Statistics\Average::generalizedMean ( array  $numbers,
float  $p 
)
static

Generalized mean (power mean, Hölder mean) https://en.wikipedia.org/wiki/Generalized_mean.

/ 1 n \ 1/p Mp(x) = | - ∑ xᵢᵖ| \ n ⁱ⁼¹ /

Special cases: M-∞(x) is min(x) M₋₁(x) is the harmonic mean M₀(x) is the geometric mean M₁(x) is the arithmetic mean M₂(x) is the quadratic mean M₃(x) is the cubic mean M∞(x) is max(X)

Parameters
array$numbers
float$p
Returns
float

◆ geometricMean()

static MathPHP\Statistics\Average::geometricMean ( array  $numbers)
static

Geometric mean A type of mean which indicates the central tendency or typical value of a set of numbers by using the product of their values (as opposed to the arithmetic mean which uses their sum).

https://en.wikipedia.org/wiki/Geometric_mean


Geometric mean = ⁿ√a₀a₁a₂ ⋯

Parameters
array$numbers
Returns
number|null

◆ harmonicMean()

static MathPHP\Statistics\Average::harmonicMean ( array  $numbers)
static

Harmonic mean (subcontrary mean) The harmonic mean can be expressed as the reciprocal of the arithmetic mean of the reciprocals.

Appropriate for situations when the average of rates is desired. https://en.wikipedia.org/wiki/Harmonic_mean

Parameters
array$numbers
Returns
number|null
Exceptions
Exception

◆ heronianMean()

static MathPHP\Statistics\Average::heronianMean ( float  $A,
float  $B 
)
static

Heronian mean https://en.wikipedia.org/wiki/Heronian_mean __ H = ⅓(A + √AB + B)

Parameters
float$A
float$B
Returns
float

◆ identricMean()

static MathPHP\Statistics\Average::identricMean ( float  $x,
float  $y 
)
static

Identric mean https://en.wikipedia.org/wiki/Identric_mean


1 / xˣ I(x,y) = - ˣ⁻ʸ/ – ℯ √ yʸ

Parameters
float$x
float$y
Returns
float
Exceptions
Exception

◆ interquartileMean()

static MathPHP\Statistics\Average::interquartileMean ( array  $numbers)
static

Interquartile mean (IQM) A measure of central tendency based on the truncated mean of the interquartile range.

Only the data in the second and third quartiles is used (as in the interquartile range), and the lowest 25% and the highest 25% of the scores are discarded. https://en.wikipedia.org/wiki/Interquartile_mean

Parameters
array$numbers
Returns
float
Exceptions
Exception

◆ iqm()

static MathPHP\Statistics\Average::iqm ( array  $numbers)
static

IQM (Interquartile mean) Convenience function for interquartileMean.

Parameters
array$numbers
Returns
float
Exceptions
Exception

◆ kthSmallest()

static MathPHP\Statistics\Average::kthSmallest ( array  $numbers,
int  $k 
)
static

Return the kth smallest value in an array Uses a linear-time algorithm: O(n) time in worst case.

if $a = [1,2,3,4,6,7]

kthSmallest($a, 4) = 6

Algorithm: 1) If n is small, just sort and return 2) Otherwise, group into 5-element subsets and mind the median 3) Find the median of the medians 4) Find L and U sets

  • L is numbers lower than the median of medians
  • U is numbers higher than the median of medians 5) Recursive step
  • if k is the median of medians, return that
  • Otherwise, recusively search in smaller group.
Parameters
array$numbers
int$kzero indexed
Returns
number|null

◆ lehmerMean()

static MathPHP\Statistics\Average::lehmerMean ( array  $numbers,
  $p 
)
static

Lehmer mean https://en.wikipedia.org/wiki/Lehmer_mean.

∑xᵢᵖ Lp(x) = ---— ∑xᵢᵖ⁻¹

Special cases: L-∞(x) is the min(x) L₀(x) is the harmonic mean L½(x₀, x₁) is the geometric mean if computed against two numbers L₁(x) is the arithmetic mean L₂(x) is the contraharmonic mean L∞(x) is the max(x)

Parameters
array$numbers
float$p
Returns
float

◆ logarithmicMean()

static MathPHP\Statistics\Average::logarithmicMean ( float  $x,
float  $y 
)
static

Logarithmic mean A function of two non-negative numbers which is equal to their difference divided by the logarithm of their quotient.

https://en.wikipedia.org/wiki/Logarithmic_mean

Mlm(x, y) = 0 if x = 0 or y = 0 x if x = y otherwise:

y - x

ln y - ln x

Parameters
float$x
float$y
Returns
float

◆ mean()

static MathPHP\Statistics\Average::mean ( array  $numbers)
static

Calculate the mean average of a list of numbers.

∑⟮xᵢ⟯ x̄ = --— n

Parameters
array$numbers
Returns
float|null

◆ median()

static MathPHP\Statistics\Average::median ( array  $numbers)
static

Calculate the median average of a list of numbers.

Parameters
array$numbers
Returns
number|null

◆ mode()

static MathPHP\Statistics\Average::mode ( array  $numbers)
static

Calculate the mode average of a list of numbers If multiple modes (bimodal, trimodal, etc.), all modes will be returned.

Always returns an array, even if only one mode.

Parameters
array$numbers
Returns
array of mode(s)

◆ powerMean()

static MathPHP\Statistics\Average::powerMean ( array  $numbers,
float  $p 
)
static

Power mean (generalized mean) Convenience method for generalizedMean.

Parameters
array$numbers
float$p
Returns
float

◆ quadraticMean()

static MathPHP\Statistics\Average::quadraticMean ( array  $numbers)
static

Quadradic mean (root mean square) Convenience function for rootMeanSquare.

Parameters
array$numbers
Returns
float

◆ rootMeanSquare()

static MathPHP\Statistics\Average::rootMeanSquare ( array  $numbers)
static

Root mean square (quadratic mean) The square root of the arithmetic mean of the squares of a set of numbers.

https://en.wikipedia.org/wiki/Root_mean_square


/x₁+²x₂²+ ⋯ x rms = / --------— √ n

Parameters
array$numbers
Returns
float

◆ simpleMovingAverage()

static MathPHP\Statistics\Average::simpleMovingAverage ( array  $numbers,
int  $n 
)
static

Simple n-point moving average SMA The unweighted mean of the previous n data.

First calculate initial average: ⁿ⁻¹ ∑ xᵢ ᵢ₌₀

To calculating successive values, a new value comes into the sum and an old value drops out: SMAtoday = SMAyesterday + NewNumber/N - DropNumber/N

Parameters
array$numbers
int$nn-point moving average
Returns
array of averages for each n-point time period

◆ trimean()

static MathPHP\Statistics\Average::trimean ( array  $numbers)
static

Trimean (TM, or Tukey's trimean) A measure of a probability distribution's location defined as a weighted average of the distribution's median and its two quartiles.

https://en.wikipedia.org/wiki/Trimean

 Q₁ + 2Q₂ + Q₃

TM = ----------— 4

Parameters
array$numbers
Returns
float

◆ truncatedMean()

static MathPHP\Statistics\Average::truncatedMean ( array  $numbers,
int  $trim_percent 
)
static

Truncated mean (trimmed mean) The mean after discarding given parts of a probability distribution or sample at the high and low end, and typically discarding an equal amount of both.

This number of points to be discarded is given as a percentage of the total number of points. https://en.wikipedia.org/wiki/Truncated_mean

Trim count = floor( (trim percent / 100) * sample size )

For example: [8, 3, 7, 1, 3, 9] with a trim of 20% First sort the list: [1, 3, 3, 7, 8, 9] Sample size = 6 Then determine trim count: floot(20/100 * 6 ) = 1 Trim the list by removing 1 from each end: [3, 3, 7, 8] Finally, find the mean: 5.2

Parameters
array$numbers
int$trim_percentPercent between 0-99
Returns
float
Exceptions
Exception

◆ weightedMean()

static MathPHP\Statistics\Average::weightedMean ( array  $numbers,
array  $weights 
)
static

Calculate the weighted mean average of a list of numbers https://en.wikipedia.org/wiki/Weighted_arithmetic_mean.

∑⟮xᵢwᵢ⟯ x̄ = --— ∑⟮wᵢ⟯

Parameters
array$numbers
array$weights
Returns
number|null
Exceptions
Exception

◆ weightedMovingAverage()

static MathPHP\Statistics\Average::weightedMovingAverage ( array  $numbers,
int  $n,
array  $weights 
)
static

Weighted n-point moving average (WMA)

Similar to simple n-point moving average, however, each n-point has a weight associated with it, and instead of dividing by n, we divide by the sum of the weights.

Each weighted average = ∑(weighted values) / ∑(weights)

Parameters
array$numbers
int$nn-point moving average
array$weightsWeights for each n points
Returns
array of averages
Exceptions
Exception

The documentation for this class was generated from the following file: