---
title: "ADA1: Class 09, Linear Regression"
author: anonymous
date: "9/20/2016"
output:
html_document:
toc: true
---
# Rubric
## Part 1, simple linear regression intuition-building exercise
(15-20 min)
Use this Shiny app to answer the next three questions.
http://sites.uclouvain.be/selt/files/medias/unamur-regression-lineaire-module20.swf
Each person do these, have your partner check your work.
Give each other a thumbs up when you've got it!
1. With 3 points, use the arrow controls in the bottom-right to move and rotate the
line to have y = 0 + 1 x with mean $\bar{x}=100$ and $\bar{y}=100$,
and $r=1$ (slope and correlation should be exact, intercept and means should be within 1 unit).
(If you accidentally move the points off the line,
update the number of points twice to have the points replaced on the line.)
2. Click the leverage button. Leverage is a measure of how much a point is an
outlier (extreme) in the $x$ direction. It's called leverage because points
with high leverage potentially have a lot of influence on the regression line
slope, pulling it up or down like a lever.
a. With 5 points, move the points to have correlation $r=-0.5$, one point
has huge leverage and the rest have small leverages.
b. With 5 points, move the points to have correlation $r=-0.5$, each point
has roughly equal leverage --- largest diameter not more than 3x the smallest.
3. Move the points to make $r < 0$ and a positive slope.
## Part 2, interpretting analysis
### Five questions to answer (answer in this document, compile to html, and submit to UNM Learn).
1. (2 p) Write regression equation.
2. (2 p) Interpret slope.
3. (2 p) Interpret R2
4. (3 p) Complete this table of predictions.
`agewks` | `shearpsi`
-|-
5|?
20|?
40|?
5. (1 p) Predictions: How comfortable do you feel about each of these predictions?
* `agewks` = 5:
* `agewks` = 20:
* `agewks` = 40:
### Data and output
A rocket motor is manufactured by bonding an igniter propellant and a sustainer
propellant together inside a metal housing. The shear strength of the bond
between the two types of propellant is an important quality characteristic. It
is suspected that shear strength is related to the age in weeks of the batch of
sustainer propellant. Twenty observations on these two characteristics are
given below. The first column is shear strength in psi (`shearpsi`), the second is age of
propellant in weeks (`agewks`).
```{R}
## Save the Rmd and .dat the ADA_WS_09_Data-BrainSizeData.csv data file to your computer
# this file uses spaces as delimiters, so use read.table()
rocket <- read.table("ADA1_WS_09_Data-RocketPropellant.dat", header = TRUE)
str(rocket)
head(rocket)
library(ggplot2)
p <- ggplot(rocket, aes(x = agewks, y = shearpsi))
p <- p + geom_point()
p <- p + geom_smooth(method = lm, se = FALSE, fullrange = TRUE)
p <- p + xlim(0,NA)
print(p)
# fit the simple linear regression model
lm.shearpsi.agewks <- lm(shearpsi ~ agewks, data = rocket)
# use summary() to parameters estimates (slope, intercept) and other summaries
summary(lm.shearpsi.agewks)
```