Python statistics | pvariance()
Prerequisite : Python statistics | variance()
pvariance() function helps to calculate the variance of an entire, rather than that of a sample. The only difference between variance() and pvariance() is that while using variance(), only the sample mean is taken into consideration, while during pvariance(), the mean of entire population is taken into consideration.
Population variance is just similar to sample variance, it tells how data points in a specific population are spread out. It is the average of the distance from the data-points to the mean of the data-set, squared. The population variance is a parameter of the population and is not dependent on research methods or sampling practices.
Syntax : pvariance( [data], mu)
[data] : An iterable with real valued numbers.
mu (optional): Takes actual mean of data-set/ population as value.
Returnype : Returns the actual population variance of the values passed as parameter.
StatisticsError is raised for data-set less than 2-values passed as parameter.
Impossible values when the value provided as mu doesn’t match actual mean of the data-set.
Code #1 :
Population variance is 0.6658984375
Code #2 : Demonstrates pvariance() on a different range of population trees.
Population variance of set 1 is 7.913043478260869 Population variance of set 2 is 7.204152249134948 Population variance of set 3 is 103889/360000 Population variance of set 4 is 21.767923875432526
Code #3 : Demonstrates the use of mu parameter.
Population Variance is 14.30385015608741
Code #4 : Demonstrate the difference between pvariance() and variance()
Variance of the whole population is 0.6127751479289941 Variance of the sample from population is 0.8286277777777779 Difference in Population variance and Sample variance is 0.21585262984878373
Note : We can see from the above sample example that Population Variance and Sample Variance doesn’t differ by a huge value.
Code #5 : Demonstrates StatisticsError
Traceback (most recent call last): File "/home/fa112e1405f09970eeddd48214318a3c.py", line 10, in print(statistics.pvariance(pop)) File "/usr/lib/python3.5/statistics.py", line 603, in pvariance raise StatisticsError('pvariance requires at least one data point') statistics.StatisticsError: pvariance requires at least one data point
The applications of Population Variance is much similar to Sample Variance, although the range of population variance is much larger than sample variance. Population variance is only to be used when the variance of an entire population is to be calculated, otherwise for calculating the variance of a sample, variance() is preferred. Population Variance is a very important tool in Statistics and handling huge amounts of data. Like, when the omniscient mean is unknown (sample mean) then variance is used as biased estimator.
Please Login to comment...