LoslegenKostenlos loslegen

Visualizing bivariate relationships

If you want to go even further than simply plotting variables and instead investigate whether any relationship exists between 2 variables, you can draw a scatterplot. This is a graph where the values of two variables are plotted along two axes.

The pattern of the resulting points is used to reveal the presence of any correlation; usually, a regression line is added to identify the tendency, if there is any:

  • An upward sloping regression line indicates a positive linear relationship between A and B (when A goes up B tends to goes up as well)
  • A downward sloping regression line indicates a negative linear relationship between A and B

You can draw a scatterplot and then create a regression model with the following functions:

plot(x = A, y = B)
lm(B ~ A)

In this exercise, you will draw a scatterplot and regression line for the return series for the SP500 (sp500) and Citigroup (citi) from January 2015 to January 2017, both of which are provided in your workspace

Diese Übung ist Teil des Kurses

Visualizing Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

  • Draw a scatterplot with sp500 on the x-axis and citi on the y-axis.
  • Add a regression line of citi against sp500 using lm() and abline().
    • Specify the regression as the reg argument to abline().
    • Make this line red and twice as thick as the default.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Draw the scatterplot


# Draw a regression line
Code bearbeiten und ausführen