Get startedGet started for free

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.

This exercise is part of the course

Foundations of Inference in Python

View Course

Exercise instructions

  • Create a line graph with two lines, one for houston_rents and one for lasvegas_rents, using the dates 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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
____
Edit and Run Code