Get startedGet started for free

Multiple regression

When there are more than one explanatory variables in the linear model, it is called multiple regression. In R, it is easy to include more than one explanatory variables in your linear model. This is done by simply defining more explanatory variables with the formula argument of lm(), as below

y ~ x1 + x2 + ..

Here y is again the target variable and x1, x2, .. are the explanatory variables.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Draw a plot matrix of the learning2014 data with ggpairs()
  • Fit a regression model where points is the target variable and both attitude and stra are the explanatory variables.
  • Print out a summary of the model.
  • Adjust the code: Add one more explanatory variable to the model. Based on the plot matrix, choose the variable with the third highest (absolute) correlation with the target variable and use that as the third variable.
  • Print out a summary of the new model.

Hands-on interactive exercise

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

# learning2014, GGally, ggplot2 are avaiable

# create an plot matrix with ggpairs()
ggpairs(learning2014, lower = list(combo = wrap("facethist", bins = 20)))

# create a regression model with multiple explanatory variables
my_model2 <- lm(points ~ attitude + stra, data = learning2014)

# print out a summary of the model

Edit and Run Code