Exercise 1
If a baseball team’s OBP is 0.361 and SLG is 0.409, how many runs do we expect the team to score?
Using the linear regression model constructed during the lecture (the one that uses OBP and SLG as independent variables), find the number of runs we expect the team to score:
runsScoredModel <- lm(RS ~ OBP + SLG, data = baseball)
summary(runsScoredModel)
Call:
lm(formula = RS ~ OBP + SLG, data = baseball)
Residuals:
Min 1Q Median 3Q Max
-78.365 -16.821 -1.208 16.477 92.684
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -811.66 16.75 -48.47 <2e-16 ***
OBP 2830.70 77.94 36.32 <2e-16 ***
SLG 1517.58 35.17 43.15 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 25.12 on 1229 degrees of freedom
Multiple R-squared: 0.9248, Adjusted R-squared: 0.9247
F-statistic: 7557 on 2 and 1229 DF, p-value: < 2.2e-16
newTeamOffense <- data.frame(OBP = 0.361, SLG = 0.409)
predict(runsScoredModel, newdata = newTeamOffense)
1
830.9116
Exercise 2
If a baseball team’s opponents OBP (OOBP) is 0.267 and opponents SLG (OSLG) is 0.392, how many runs do we expect the team to allow?
Using the linear regression model discussed during the lecture (the one on the last slide of the previous video), find the number of runs we expect the team to allow.
runsAllowedModel <- lm(RA ~ OOBP + OSLG, data = baseball)
summary(runsAllowedModel)
Call:
lm(formula = RA ~ OOBP + OSLG, data = baseball)
Residuals:
Min 1Q Median 3Q Max
-76.805 -18.208 0.146 19.706 72.286
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -877.61 29.36 -29.89 <2e-16 ***
OOBP 2864.60 156.04 18.36 <2e-16 ***
OSLG 1632.76 90.03 18.14 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 27.18 on 417 degrees of freedom
(812 observations deleted due to missingness)
Multiple R-squared: 0.9042, Adjusted R-squared: 0.9038
F-statistic: 1969 on 2 and 417 DF, p-value: < 2.2e-16
newTeamDefense <- data.frame(OOBP = 0.267, OSLG = 0.392)
predict(runsAllowedModel, newdata = newTeamDefense)
1
527.2847
This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.