<jupyter_start><jupyter_text>Measures of Variability The measures of dispersion give a quantitative measure of the spread of a distribution. They provide an idea of whether the values in a distribution are situated around the central value or spread out. The following are the commonly used measures ofdispersion.**Range:** The range is a measure of the difference between the lowest and highest values in a dataset.  **Interquartile range:** A measure of the difference between the third quartile and the first quartile. This measure is less affected by extreme values since it focuses on the values lying in the middle. The interquartile range is a good measure for skewed distributions that have outliers. The interquartile range is denoted by  $IQR = Q_3 - Q_1.$**Variance:** This is a measure of how much values in a dataset are scattered around the mean value. The value of the variance is a good indication of whether the mean is representative of values in the dataset. A small variance would indicate that the mean is an appropriate measure of central tendency. The following formula gives the variance:    $$\sigma^2 = \frac{\sum (x-\mu)^2}{N}$$    Where $\mu$ is the mean, and $N$ is the number of values in the dataset.**Sample Variance** is given by:$$S^2 = \frac{\sum (x-\overline x)^2}{n-1}$$Where $\overline x$ is the sample mean, and $n$ is the number of values in the sample.**Standard deviation:** This measure is calculated by taking the square root of the variance. The variance is not in the same units as the data since it takes the square of the differences; hence taking the square root of the variance brings it to the same units as the data. For instance, in a dataset about the average rainfall in centimeters, the variance would give the value in $cm^2$, which would not be interpretable, while the standard deviation in $cm$ would give an idea of the average rainfall deviation in centimeters.**Skewness:** This measures the degree of asymmetry of a distribution![](https://upload.wikimedia.org/wikipedia/commons/c/cc/Relationship_between_mean_and_median_under_different_skewness.png)**Positive Skewness:** A positively skewed distribution is characterized by many outliers in the upper region, or right tail. A positively skewed distribution is said to be skewed right because of its relatively long upper (right) tail.**Negative Skewness:** A negatively skewed distribution has a disproportionately large amount of outliers that fall within its lower (left) tail. A negatively skewed distribution is said to be skewed left because of its long lower tail.**Kurtosis:**  Kurtosis is a measure of whether a given distribution of data is curved, peaked, or flat.![](https://brewcode.stringlab.org/wp-content/uploads/2020/08/image-28.png)<jupyter_code>import pandas as pd
data = pd.Series([19,23,19,18,25,16,17,19,15,23,21,23,21,11,6])
data.describe()
data.mode()<jupyter_output><empty_output><jupyter_text>The values 19 and 23 are the most frequently occurring values<jupyter_code>data.median()
range_data = max(data)-min(data)
range_data
data.std()
data.var()
from scipy.stats import skew, kurtosis

skew(data), kurtosis(data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07409733124018839, 'fraction_numerical': 0.015384615384615385, 'mean_word_length': 5.247058823529412, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '470136', 'license': 'MIT', 'n_tokens_mistral': 869, 'n_tokens_neox': 785, 'n_words': 430, 'path': '07. Measures of Variability.ipynb', 'repo_name': 'luckyrabbit85/Statistics-For-Data-Science', 'size': '3185'}