Q-Q plot
Another way to examine the normality of a distribution is with a Q-Q (quantile-quantile) plot. For this exercise, you will create a Q-Q plot for the country-level Unemployment
data you saw in the last exercise (available in your workspace as countrydata
). The Q-Q plot compares the theoretical quantiles expected under a normal distribution to the actual observed values (ordered). When a distribution is normally distributed, you will see a straight line. The more crooked the line is, the farther the distribution departs from normality. pandas
and scipy.stats
have been loaded into the workspace as pd
and stats
.
This exercise is part of the course
Performing Experiments in Python
Exercise instructions
- Calculate the theoretical quantiles for a normal distribution.
- Create a DataFrame including your theoretical quantiles and the ordered values for
Unemployment
. - Create and print a Q-Q plot using your DataFrame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate theoretical quantiles
tq = stats.probplot(____, dist=____)
# Create Dataframe
df = pd.DataFrame(data= {'Theoretical Quantiles': ____,
"Ordered Values": ____.sort_values() })
# Create Q-Q plot
print(p9.ggplot(____)+ p9.aes(____) +p9.____)