Testing for correlation
You want to understand if rent prices in Las Vegas and Houston are correlated or not. If you see prices rising in Las Vegas, is it reasonable to assume they are also rising in Houston? A NumPy array of rents has been loaded for Las Vegas (lasvegas_rents
) and Houston (houston_rents
), as well as the dates
associated with each measurement.
The packages pandas as pd
, NumPy as np
, Matplotlib as plt
, and the stats
package from SciPy have all been loaded for you.
Diese Übung ist Teil des Kurses
Foundations of Inference in Python
Anleitung zur Übung
- Create a line graph with two lines, one for
houston_rents
and one forlasvegas_rents
, using thedates
on the x-axis. - Compute the Pearson correlation coefficient and its associated p-value.
- Determine and print out a Boolean that tells you whether the p-value is significant at the 5% level.
- Print out R-squared.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Create a line graph showing the rents for both San Francisco and Las Vegas
____(____, ____, label='Houston')
____(____, ____, label='Las Vegas')
plt.show()
# Compute the Pearson correlation coefficient R, as well as the p-value
r, p_value = ____(____, ____)
# Print if the p-value is less than alpha = 5%
____
# Print out R-squared
____