Find Sample Variance using Python

Sample Variance:

Sample variance is a statistic, which measures the dispersion in a Sample.

Sample variance is used as an estimator of the population variance.

Sample variance s2 is given by the formula

s2 = i(1 to n)(xi-)2/n-1

 

The reason the denominator has n-1 instead of n is because usage of n

in the denominator underestimates the population variance. Using n-1 makes the Sample Variance an unbiased estimator of the Population Variance.

 

Method Name:

variance(data)

 

Method Overview:

The variance() function takes a sequence or an iterator as the parameter containing the sample data and returns the sample variance.

 

Exceptions:

Python raises a StatisticsError if the data passed inside the variance() is empty

 

Python Example Program to find sample variance:

 

# import the statistics module

import statistics

 

sampleData = [55,56,54,53,52,67,56,62,59]

 

sampleVariance = statistics.variance(sampleData)

 

print("Sample variance of the distribution is %.2f"%(sampleVariance))

 

 

Example Python program output that finds the sample variance:

 

Sample variance of the distribution is 23.11

 


Copyright 2024 © pythontic.com