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.
Este ejercicio forma parte del curso
Helsinki Open Data Science
Instrucciones del ejercicio
- Draw a plot matrix of the learning2014 data with
ggpairs() - Fit a regression model where
pointsis the target variable and bothattitudeandstraare 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.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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