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.
Deze oefening maakt deel uit van de cursus
Foundations of Inference in Python
Oefeninstructies
- Create a line graph with two lines, one for
houston_rentsand one forlasvegas_rents, using thedateson 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.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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
____