# Multiple Regression (Part 1)

**R-exercises**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In the exercises below we cover some material on multiple regression in R.

Answers to the exercises are available here.

If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.

We will be using the dataset `state.x77`

, which is part of the `state`

datasets available in `R`

. (Additional information about the dataset can be obtained by running `help(state.x77)`

.)

**Exercise 1**

a. Load the `state`

datasets.

b. Convert the `state.x77`

dataset to a dataframe.

c. Rename the `Life Exp`

variable to `Life.Exp`

, and `HS Grad`

to `HS.Grad`

. (This avoids problems with referring to these variables when specifying a model.)

**Exercise 2**

Suppose we wanted to enter all the variables in a first-order linear regression model with `Life Expectancy`

as the dependent variable. Fit this model.

**Exercise 3**

Suppose we wanted to remove the `Income`

, `Illiteracy`

, and `Area`

variables from the model in Exercise 2. Use the `update`

function to fit this model.

**Learn more**about multiple linear regression in the online course Linear regression in R for Data Scientists. In this course you will learn how to:

- Model basic and complex real world problem using linear regression
- Understand when models are performing poorly and correct it
- Design complex models for hierarchical data
- And much more

**Exercise 4**

Let’s assume that we have settled on a model that has `HS.Grad`

and `Murder`

as predictors. Fit this model.

**Exercise 5**

Add an interaction term to the model in Exercise 4 (3 different ways).

**Exercise 6**

For this and the remaining exercises in this set we will use the model from Exercise 4.

Obtain 95% confidence intervals for the coefficients of the two predictor variables.

**Exercise 7**

Predict the Life Expectancy for a state where 55% of the population are High School graduates, and the murder rate is 8 per 100,000.

**Exercise 8**

Obtain a 98% confidence interval for the mean Life Expectancy in a state where 55% of the population are High School graduates, and the murder rate is 8 per 100,000.

**Exercise 9**

Obtain a 98% confidence interval for the Life Expectancy of a person living in a state where 55% of the population are High School graduates, and the murder rate is 8 per 100,000.

**Exercise 10**

Since our model only has two predictor variables, we can generate a 3D plot of our data and the fitted regression plane. Create this plot.

**leave a comment**for the author, please follow the link and comment on their blog:

**R-exercises**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.