SciPy stats.sem Function
SEM
in statistics stands for Standard Error of the Mean
. SEM
is calculated by calculating the standard deviation of the given data and then dividing it by the square root of the size of the given data. This standard error helps in finding out the accuracy of the arithmetic mean of the sample data. This is done by finding out the variability between each sample in the given data.
So, as the size of the given sample data increases, the value of the SEM
decreases.
the scipy.stats.sem
Function
The scipy.stats.sem
function of the SciPy
library helps calculate the SEM
i.e Standard Mean Error
of the given input data.
Syntax
scipy.stats.sem(a, axis=0, ddof=0, nan_policy="propagate")
Parameter
a (array) |
This parameter defines the input data for which the SEM value is calculated. |
|
axis (int) |
This parameter defines the axis along which the SEM value of the input data is calculated. The default value of this parameter is 0 . If the value is None , then the function simply computes over the whole input data. |
|
ddof (int) |
ddof stands for Delta degrees-of-freedom . This parameter defines the number of degrees-of-freedom that helps in adjusting the bias with limited input samples relative to the population’s variance. The default value of this parameter is 1 . |
|
nan_policy |
This parameter decides how to deal when there are NaN values in the input data. There are three decision parameters in the parameter, propagate , raise , omit . propagate simply returns the NaN value, raise returns an error and omit simply ignores the NaN values and the function continues with computation. These decision parameters are defined in single quotes '' . The default value of this parameter is propagate . |
All the parameters except the a (array)
parameter are optional. This means that it is not necessary to define all the parameters whenever using this function.
Example of Standard Error of the Mean
import numpy as np
from scipy import stats
array_1 = [[15, 12, 17, 11, 4], [43, 5, 2, 36, 21]]
array_2 = [23, 35, 14, 11, 2]
print("array 1 : ", array_1)
print("array 2 : ", array_2)
print("SEM for array 1 : ", stats.sem(array_1, axis=1, ddof=1))
print("SEM for array 2 : ", stats.sem(array_2, axis=0, ddof=0))
Output:
array 1 : [[15, 12, 17, 11, 4], [43, 5, 2, 36, 21]]
array 2 : [23, 35, 14, 11, 2]
SEM for array 1 : [2.22261108 8.14002457]
SEM for array 2 : 5.019960159204453
Lakshay Kapoor is a final year B.Tech Computer Science student at Amity University Noida. He is familiar with programming languages and their real-world applications (Python/R/C++). Deeply interested in the area of Data Sciences and Machine Learning.
LinkedIn