-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLRLakers.Rmd
93 lines (57 loc) · 2.46 KB
/
MLRLakers.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: "Lakers2122"
author: ""
date: "`r Sys.Date()`"
output: html_document
---
```{r Preparing Lakers Dataset}
library("corrplot")
library("car")
library("MASS")
library("ggplot2")
library("faraway")
#load lakers dataset into R
lakers = read.csv("Lakers2122_.csv", header=TRUE)
head(lakers, n = 5)
dim(lakers) #dimensions of set
#summary of lakers dataset
summary(lakers)
#selects specific data frame from data set over a range of columns
lakdf=lakers[,3:24]
summary(lakdf)
#full model
lm_full=lm(PTS.G ~ . , data=lakdf)
#correlation plot for selected data frame
corr <- round(cor(lakdf, use = "pairwise.complete.obs"), 2)
#color corrplot
corrplot(corr, method = c("color"), type = c("full"), tl.srt = 45, order= 'AOE', addrect = 2, rect.col = 'black', diag = TRUE, tl.pos='d', insig='label_sig', number.cex=0.43, is.corr = TRUE, bg = 'grey')
#numerical corrplot
corrplot(corr, method = c("number"), type = c("full"), title= "Correlation Matrix for Lakers Shooting Predictors", tl.srt = 45, order= 'AOE', addrect = 2, rect.col = 'black', diag = TRUE, tl.pos='d', insig='label_sig', number.cex=0.43, is.corr = TRUE, bg = 'grey')
#It is hard to visualize because many predictors are perfectly correlated producing aliasing so I had to do process of elimination for each predictor.
#model removing highly correlated predictors
#linear model 1 removing predictors I was not interested in: Minutes, Field Goals Made, Field Goal Attempt, Three Point Attempt, Three Point Percentage, Free throw Made, Free Throw Attempt, Offensive Rebound, Defensive Rebound, Rebounding Assists, Turnovers were all removed.
lm_1 = lm(PTS.G ~ . -MIN -FGM -FGA -thrptmd -thrptatt -thrpt_per -freethrowmd -freethrowatt -OREB -DREB -REB -AST -TOV, data=lakdf)
#summary of lm1
summary(lm_1)
#summary(powerTransform(lm_12))
#performance check of this model
performance::check_model(lm_1)
summary(lm_1)
#plot showing q-q, hist, other important stats
plot(lm_1)
```
```{r}
#model removing highly correlated predictors
#
lm_3 =lm(PTS.G^0.5 ~ . -MIN -FGM -FGA -thrptmd -thrptatt -thrpt_per -freethrowmd -freethrowatt -OREB -DREB -REB -AST -TOV, data=lakdf)
#remove fg_per
lm_4 =lm(PTS.G^0.5 ~ . -MIN -FGM -FGA -thrptmd -thrptatt -thrpt_per -freethrowmd -freethrowatt -OREB -DREB -REB -AST -TOV -fg_per, data=lakdf)
anova(lm_3, lm_4)
#summary stats of model 3 and 4
summary(lm_3)
summary(lm_4)
#performance check of final model
performance::check_model((lm_4))
#normal qq plot and plot of residuals
plot(lm_4)
```