14 Linear Regression with mtcars
Remember: ~
here means “explained by”, so the formula mpg ~ wt means we are predicting mpg as explained by wt. The most helpful way to view the output is with:
14.1 Excercises for you
14.1.1 mtcars
- Which variable in the
mtcars
dataset do you think best predictsmpg
and why? - What
mpg
would you predict for a car with a displacement of 333? - What
mpg
would you predict for a car with a displacement of 12 cylinders? - What
mpg
would you predict for a car with a displacement of 333 and 12 cylinders? - What
mpg
would you predict for a car with a displacement of 333, 12 cylinders, and weighs 4,000 pounds?
14.1.2 trees
Open the trees
dataset in R.
- What are the variables and what do they mean?
- Make a plot with Volume on the x axis and Height on the Y and add a best fit line.
- Use Girth and Height to predict Volume. What would you predict for a tree with a Girth of 10 and a Height of 100 feet?
- Use Girth and Height to predict Volume. What would you predict for a tree with a Girth of 10 and a Height of 15 meters?
- What is the maximum circumference of a tree in this dataset?
14.2 More Excercises for you
1.Open the women
data set. Add a new variable (column) to the women
dataframe called GPA which is these 15 numbers: 1.5, 3.7, 4,1, 3, 2.5, 3.8, 0.8, 2, 4, 1, 3, 2.5, 3.0, 4.0. You shoud get something that looks similar to mine.
FALSE height weight GPA
FALSE 1 58 115 1.5
FALSE 2 59 117 3.7
FALSE 3 60 120 4.0
FALSE 4 61 123 1.0
FALSE 5 62 126 3.0
FALSE 6 63 129 2.5
FALSE 7 64 132 3.8
FALSE 8 65 135 0.8
FALSE 9 66 139 2.0
FALSE 10 67 142 4.0
FALSE 11 68 146 1.0
FALSE 12 69 150 3.0
FALSE 13 70 154 2.5
FALSE 14 71 159 3.0
FALSE 15 72 164 4.0
Use GPA and weight to predict the height of a person who is 155 pounds and has a GPA if 3.33. What is your prediction?
Is GPA a significant predictor of height and how do you know?
Create a figure showing a best fit line on of height and GPA.
Install the dplyr package into your Rstudio session.