## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## Rows: 2455 Columns: 24
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): TEAM, CONF, POSTSEASON
## dbl (21): G, W, ADJOE, ADJDE, BARTHAG, EFG_O, EFG_D, TOR, TORD, ORB, DRB, FT...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mod <- lm(WAB ~ ADJOE, data = bball)
summary(mod)
##
## Call:
## lm(formula = WAB ~ ADJOE, data = bball)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.1204 -2.5203 -0.0016 2.5731 13.3365
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -89.66782 1.07363 -83.52 <2e-16 ***
## ADJOE 0.79247 0.01037 76.44 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.788 on 2453 degrees of freedom
## Multiple R-squared: 0.7043, Adjusted R-squared: 0.7042
## F-statistic: 5844 on 1 and 2453 DF, p-value: < 2.2e-16
ggplot(data = bball, aes(x = ADJOE, y = WAB, color = WAB))+
geom_point()+
geom_abline(intercept = mod$coefficients[1], slope = mod$coefficients[2])
##Create an ANOVA table and produce the F-statistic and discuss the R-squared ##value
anova(mod)
## Analysis of Variance Table
##
## Response: WAB
## Df Sum Sq Mean Sq F value Pr(>F)
## ADJOE 1 83867 83867 5843.8 < 2.2e-16 ***
## Residuals 2453 35204 14
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# QQ NORM Plot
hist(mod$residuals)
qqnorm(mod$residuals)
qqline(mod$residuals)
bball<-cbind(bball,
fit=mod$fitted.values,
residual=mod$residuals)
ggplot(data=bball, aes(residual))+
geom_histogram(bins=8)+
ggtitle("Histogram of Residuals")+
theme_bw()
# Residual Plot
ggplot(data=bball, aes(WAB, residual))+
geom_point()+
ggtitle("Residual Plot")+
xlab("WAB (Wins above bubble)")+
ylab("Residuals")+
theme_bw()+
geom_hline(yintercept = 0,
color="blue", lty=2, lwd=1)
##Summary of findings: