Oihana PHP

stddev.php

Table of Contents

Functions

stddev()  : float
Computes the standard deviation of a list of numbers.

Functions

stddev()

Computes the standard deviation of a list of numbers.

stddev(array<int, int|float> $values[, bool $sample = false ]) : float

The standard deviation is the square root of the variance(). By default the population standard deviation is returned ; when $sample is true, the sample standard deviation is returned (Bessel's correction, N - 1).

Parameters
$values : array<int, int|float>

A list of numeric values (at least one for population, two for sample).

$sample : bool = false

Whether to compute the sample standard deviation (N - 1) instead of the population one (N).

Tags
throws
InvalidArgumentException

If the array is empty, or has fewer than two values when $sample is true.

example
use function oihana\core\maths\stddev;

echo stddev( [ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ] )        ; // 2.0   (population)
echo stddev( [ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ] , true ) ; // ~2.138 (sample)
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
float

The standard deviation of the values.

On this page

Search results