moneyball <- read.csv("baseball.csv")
#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:
RS_reg <- lm(RS ~ OBP + SLG, data = moneyball)
summary(RS_reg)
Call:
lm(formula = RS ~ OBP + SLG, data = moneyball)
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
(Intercept) -811.66 OBP 2830.70 SLG 1517.58
predict(RS_reg, newdata = data.frame(OBP = 0.361, SLG = 0.409))
1
830.9116
831 runs
#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.
RA_reg <- lm(RA ~ OOBP + OSLG, data = moneyball)
summary(RA_reg)
Call:
lm(formula = RA ~ OOBP + OSLG, data = moneyball)
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
(Intercept) -877.61
OOBP 2864.60
OSLG 1632.76
RA=−837.38+2913.60×OOBP+1514.29×OSLG
# Given values
OOBP <- 0.267
OSLG <- 0.392
# Regression equation
RA <- -877.61 + 2864.60 * OOBP + 1632.76 * OSLG
# Display result
RA
[1] 527.2801