stats_variance

(PECL stats >= 1.0.0)

stats_varianceReturns the variance

说明

float stats_variance ( array $a [, bool $sample = false ] )

Returns the variance of the values in a.

参数

a

The array of data to find the standard deviation for. Note that all values of the array will be cast to float.

sample

Indicates if a represents a sample of the population; defaults to FALSE.

返回值

Returns the variance on success; FALSE on failure.

User Contributed Notes

Anonymous 27-Feb-2009 10:43
This will return surprising values for most users, since the default of sample=false is rather unusual when speaking about variance.

Point is:
When using stats_variance($foo,TRUE) the sum is divided by n-1 while the default just divides it by n. So when you expect your variance to be lower you probable wanted to divide by n-1, therefore should set the second parameter =TRUE.