playdata3 <- data.table::fread("../input/playtrack/tracklist2.csv", stringsAsFactors = F)
final_data <- data.table::fread("../input/playtrack/final_data.csv", stringsAsFactors = F)
injury <- data.table::fread("../input/nfl-playing-surface-analytics/InjuryRecord.csv", stringsAsFactors = F)
library(dplyr)
library(ggplot2)
#velocity: calculated for each play using x-y coordinates
#acceleration : calculated for each play using x-y coordinates
#v_dirr : velocity direction angle for each play
#acc_dirr: acceleration direction angle for each play
#vdir_ch : velocity direction change for each play
#accdir_ch: acceleration direction change for each play
#aver_dir : direction change of player's motion for each play
#aver_orient : direction change of player's orientation for each play
#time : time duration for each play
#dis: distance for each play

stadfield<-ggplot(data = playdata3) + 
  geom_bar(mapping = aes(x = StadiumType, fill = FieldType))
stadfield+coord_flip()+
  ggtitle("OUTDOOR STADIUM IS THE MAJOR TYPE WITH NATURAL SURFACE") 

ggplot(playdata3, aes(Weather, velocity)) + geom_boxplot(fill = "red")+
  scale_y_continuous("velocity", breaks= seq(0,10, by=1))+
  labs(title = "EFFECT OF WEATHER ON VELOCITY", x = "Weather")

#there is little differnce in velocity across different condition





stad_vel<-ggplot(playdata3, aes(StadiumType, velocity)) + geom_boxplot(fill = "red")+
  scale_y_continuous("velocity", breaks= seq(0,10, by=1))+
  labs(title = "EFFECT OF STADIUM TYPE ON VELOCITY", x = "Stadium Type")
stad_vel+coord_flip()


#there is little differnce in velocity in different stadium types


ggplot(playdata3, aes(FieldType, velocity)) + geom_boxplot(fill = "red")+
  scale_y_continuous("velocity", breaks= seq(0,10, by=1))+
  labs(title = "EFFECT OF FIELD TYPE ON VELOCITY", x = "Field Type")

positionplot<-ggplot(playdata3, aes(Position, velocity)) + geom_boxplot(fill = "red")+
  scale_y_continuous("velocity", breaks= seq(0,10, by=1))+
  labs(title = "EFFECT OF Position TYPE ON VELOCITY", x = "Position Type")
positionplot+coord_flip()

plot5<-ggplot(playdata3, aes(RosterPosition,velocity)) + geom_boxplot(fill = "red")+
  labs(title = "EFFECT OF ROSTER POSITION ON VELOCITY", x = "Roster Position")
plot5+coord_flip()

plot7<-ggplot(playdata3, aes(PlayType,velocity)) + geom_boxplot(fill = "red")+
  labs(title = "EFFECT OF PLAY TYPE ON VELOCITY", x = "Play type")
plot7+coord_flip()

pgplot<-ggplot(playdata3, aes(PositionGroup, velocity)) + geom_boxplot(fill = "red")+
  scale_y_continuous("velocity", breaks= seq(0,10, by=1))+
  labs(title = "EFFECT OF Position Group Type ON VELOCITY", x = "Position Group Type")
pgplot+coord_flip()






ggplot(playdata3, aes(velocity)) + geom_histogram(binwidth = 2)+
  scale_x_continuous("velocity", breaks = seq(0,10,by = 1))+
  labs(title = "Velocity Histogram")

ggplot(data =playdata3) + 
  geom_smooth(mapping = aes(x = time, y =velocity))+
  ggtitle("VELOCITY DECREASES WITH TIME")

ggplot(data =playdata3) + 
  geom_smooth(mapping = aes(x = dis, y =velocity))


ggplot(data =playdata3) + 
  geom_smooth(mapping = aes(x = acceleration, y =velocity))+
  ggtitle("Positive Linear Relationship between Acceleration and Velocity")





ggplot(data = playdata3) +
  geom_smooth(mapping = aes(x = velocity, y = aver_orient, colour = FieldType))+
  labs(title = "CHANGE IN ORIENTATION VS VELOCITY", x = "velocity", y = "change in orientation")

ggplot(data = playdata3) +
  geom_smooth(mapping = aes(x = velocity, y = aver_dir, colour = FieldType))+
  labs(title = "CHANGE IN MOTION DIRECTION VS VELOCITY", x = "velocity", y = "change in motion direction")

ggplot(data = playdata3) +
  geom_smooth(mapping = aes(x = acceleration, y = aver_dir, colour = FieldType))+
  labs(title = "CHANGE IN MOTION DIRECTION VS ACCELERATION", x = "Acceleration", y = "change in motion direction")

ggplot(data = playdata3) +
  geom_smooth(mapping = aes(x = acceleration, y = aver_orient, colour = FieldType))+
  labs(title = "CHANGE IN ORIENTATION VS ACCELERATION", x = "Acceleration", y = "change in orientation")

plot3<-ggplot(playdata3, aes(StadiumType, aver_dir)) + geom_boxplot(fill = "blue")+
  labs(title = "Effect Of Stadium Type ON Change in player's Motion Direction", x = "Stadium Type", y = "Change in motion direction" )
plot3+coord_flip()

ploto<-ggplot(playdata3, aes(StadiumType, aver_orient)) + geom_boxplot(fill = "blue")+
  labs(title = "Effect Of Stadium Type ON Change in player's orientation Direction", x = "Stadium Type", y = "Change in orientation" )
ploto+coord_flip()

plotfd<-ggplot(playdata3, aes(FieldType, aver_orient)) + geom_boxplot(fill = "blue")+
  labs(title = "Effect Of Field Type ON Change in player's motion Direction", x = "Field Type", y = "Change in motion" )
plotfd+coord_flip()

plotfo<-ggplot(playdata3, aes(FieldType, aver_orient)) + geom_boxplot(fill = "blue")+
  labs(title = "Effect Of Field Type ON Change in player's orientation Direction", x = "Field Type", y = "Change in orientation" )
plotfo+coord_flip()

ggplot(playdata3, aes(Weather, acceleration)) + geom_boxplot(fill = "red")+
  labs(title = "EFFECT OF Weather ON acceleration", x = "Weather")

ggplot(playdata3, aes(FieldType, acceleration)) + geom_boxplot(fill = "red")+
  labs(title = "EFFECT OF Field Type ON acceleration", x = "Field Type")

ggplot(playdata3, aes(StadiumType, acceleration)) + geom_boxplot(fill = "red")+
  labs(title = "EFFECT OF Stadium Type ON acceleration", x = "Stadium Type")





#Velocity and acceleration models depend on stepwise model selection**
  
Model_velocity<- lm(velocity~time+dis+aver_orient+vdir_ch+accdir_ch+acceleration+as.factor(FieldType)+Temperature+ StadiumType+Weather+RosterPosition+Position+PositionGroup+PlayType+PlayerGamePlay, data = playdata3)


Model_acceleration<-lm(acceleration~aver_dir+vdir_ch+accdir_ch+velocity+dis+time+StadiumType+PlayType+RosterPosition+Position+PlayerDay+PlayerGamePlay, data = playdata3)


summary(Model_velocity)
summary(Model_acceleration)


#**velocity model**
  #-our model estimates an expected .02217 decrease in velocity for every 1 second increase in time holding other variables constant
#-our model estimates an expected 0.01625 increase in velocity for every 1 yard increase in distance holding other variables constant
#our model estimates an expected .004325 decrease in velocity for every 1 degree increase in change in orientation angle holding other variables constant
#our model estimates an expected .00331 increase in velocity for every 1 degree increase in change in velocity direction holding other variables constant
#our model estimates an expected .006577 increase in velocity for every 1 degree increase in change in acceleration direction holding other variables constant
#our model estimates an expected 3.012 increase in velocity for every 1 unit increase in acceleration holding other variables constant
#our model estimates an expected 0.01269 inccrease in velocity for being asynthetic field holding other variables constant
#our model estimates an expected 0.00001474 decrease in velocity for every 1 degree F increase in Temperature holding other variables constant
#our model estimates an expected 0.01293 decrease in velocity for being indoor closed stadium holding other variables constant
#our model estimates an expected 0.03725 increase in velocity for being indoor open stadium holding other variables constant
#our model estimates an expected 0.03179 decrease in velocity in cloudy and rain weather holding other variables constant
#our model estimates an expected 0.02035 increase in velocity for RosterPosition Defensive Lineman holding other variables constant
#our model estimates an expected 0.07337 increase in velocity for RosterPosition kicker holding other variables constant
#our model estimates an expected 0.2514 increase in velocity for RosterPosition Line backer holding other variables constant
#our model estimates an expected 0.1035 increase in velocity for RosterPosition Offensive Lineman holding other variables constant
#our model estimates an expected 0.04858 increase in velocity for RosterPosition safety holding other variables constant
#our model estimates an expected 0.05933 increase in velocity for RosterPosition Tight end holding other variables constant
#our model estimates an expected 0.08028 decrease in velocity for Position FS  holding other variables constant
#our model estimates an expected 0.04685 increase in velocity for Position ILB  holding other variables constant
#our model estimates an expected 0.07998 decrease in velocity for Position K  holding other variables constant
#our model estimates an expected 0.1089 increase in velocity for Position LB  holding other variables constant
#our model estimates an expected 0.03583 increase in velocity for Position MLB  holding other variables constant
#our model estimates an expected 0.08696 increase in velocity for Position S  holding other variables constant
#our model estimates an expected 0.01322 decrease in velocity for Position T  holding other variables constant
#our model estimates an expected 0.1672 decrease in velocity for Position Group DL  holding other variables constant
#our model estimates an expected 0.2179 decrease in velocity for Position Group LB  holding other variables constant
#our model estimates an expected 0.056 increase in velocity for play type extra point  holding other variables constant
#our model estimates an expected 0.07134 increase in velocity for play type field goal  holding other variables constant
#our model estimates an expected 0.2384 increase in velocity for play type kick off  holding other variables constant
#our model estimates an expected 0.21 increase in velocity for play type kick off not returned holding other variables constant
#our model estimates an expected 0.1894 increase in velocity for play type kick off returned holding other variables constant
#our model estimates an expected 0.1994 increase in velocity for play type punt  holding other variables constant
#our model estimates an expected 0.1934 increase in velocity for play type punt not returned  holding other variables constant
#our model estimates an expected 0.1812 increase in velocity for play type punt returned holding other variables constant
#our model estimates an expected 0.000492 decrease in velocity for every 1 play increase in plays the player has participated in during the game  holding other variables constant
#38.61% from the variation in velocity explained by deviation in our independent variables.

#**Acceleration model**
 # -our model estimates an expected .0007677 decrease in acceleration for every 1 degree increase in change in direction angle of player motion holding other variables constant
#our model estimates an expected .003436 increase in acceleration for every 1 degree increase in change in velocity direction holding other variables constant
#our model estimates an expected .0008413 decrease in acceleration for every 1 degree increase in change in acceleration direction holding other variables constant
#our model estimates an expected 0.04705 increase in acceleration for every 1 unit increase in velocity holding other variables constant
#our model estimates an expected .00153 decrease in acceleration for every 1 second increase in time holding other variables constant
#our model estimates an expected 0.001822 decrease in acceleration for being indoor closed stadium holding other variables constant
#our model estimates an expected 0.002085 decrease in acceleration for being indoor open stadium holding other variables constant
#our model estimates an expected 0.001502 decrease in acceleration for being outdoor stadium holding other variables constant
#our model estimates an expected 0.003062 decrease in acceleration for RosterPosition Line backer holding other variables constant
#our model estimates an expected 0.0116 decrease in acceleration for RosterPosition Offensive Lineman holding other variables constant
#our model estimates an expected 0.004073 increase in acceleration for RosterPosition wide reciever holding other variables constant
#our model estimates an expected 0.005167 increase in acceleration for Position DB  holding other variables constant
#our model estimates an expected 0.006817 decrease in acceleration for Position DT  holding other variables constant
#our model estimates an expected 0.002644 increase in acceleration for Position FS  holding other variables constant
#our model estimates an expected 0.01185 increase in acceleration for Position LB  holding other variables constant
#our model estimates an expected 0.006758 decrease in acceleration for Position NT  holding other variables constant
#our model estimates an expected 0.007198 increase in acceleration for Position S  holding other variables constant
#our model estimates an expected 0.000003219 decrease in acceleration for every 1 day increase in timeline of player's participation in games  holding other variables constant
#our model estimates an expected 0.00001695 decrease in acceleration for every 1 play increase in plays the player has participated in during the game  holding other variables constant
#34.48% from the variation in acceleration explained by the deviation in our independent variables.




#**Injury Assesment**

#merged the 3 files in "final_data" 




summary(final_data)

summary(injury)

 plotbb<-ggplot(data = injury) + 
   geom_bar(mapping = aes(x = BodyPart, fill = BodyPart))
 plotbb+coord_flip()+
   ggtitle("Knee and Ankle Injuries are most common in injury ")

 plotbf<-ggplot(data = injury) + 
   geom_bar(mapping = aes(x = Surface, fill = BodyPart))
 plotbf+coord_flip()+
   ggtitle("Injuries are more likely to be on Synthetic Surfaces")

injury <- injury %>% 
  mutate(severity = ifelse(DM_M42 == 1, "42", 
                           ifelse(DM_M42 == 0 & DM_M28 == 1, "28",
                                  ifelse(DM_M42 == 0 & DM_M28 == 0 & DM_M7 == 1, "7", "1"))))

 plotsev<-ggplot(data = injury) + 
   geom_bar(mapping = aes(x = severity, fill = BodyPart))
 plotsev+coord_flip()+
   ggtitle("Most injuries with [7-28] interval")

 plotdm1<-ggplot(data = injury) + 
   geom_bar(mapping = aes(x = severity, fill = BodyPart), position = "dodge")+
   scale_x_discrete("severity", breaks = seq(0,1))
 plotdm1+facet_grid(~severity)
    


#Ankle injury is most common injury for missed days less than 7
#Knee injury is most common injury for missed days more than 7 and less than 28
#Knee injury is most common injury for missed days more than 28 and less than 42
#Knee injury is most common injury for missed days more than 42



plotsev1<-ggplot(data = injury) + 
   geom_bar(mapping = aes(x = Surface, fill = severity))
 plotsev1+coord_flip()+
   ggtitle("Synthetic surface has more sever injuries")






 plotbs<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = StadiumType, fill = BodyPart))
 plotbs+coord_flip()+
   ggtitle("Injury is most common in outdoor Stadium")

 plota<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = StadiumType, fill = BodyPart))+
 facet_grid(~FieldType)
 plota+coord_flip()+
   ggtitle("Injury is most common in outdoor stadium with natural surface")

 plotc<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = Weather, fill =BodyPart))
 plotc+coord_flip()+
   ggtitle("Injury is most common in Cloudy weather")

plotd<-ggplot(final_data, aes(BodyPart,velocity)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of VELOCITY on Body Part injuries ", x = "Body Part")
 plotd+coord_flip()


plote<-ggplot(final_data, aes(BodyPart,aver_dir)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Direction change in player's motion on Body Part injuries", x = "Body Part", y =" Direction change in player's motion")
 plote+coord_flip()
```

```{r,echo=T}
final_data<- final_data %>% 
   mutate(severity = ifelse(DM_M42 == 1, "42", 
                            ifelse(DM_M42 == 0 & DM_M28 == 1, "28",
                                   ifelse(DM_M42 == 0 & DM_M28 == 0 & DM_M7 == 1, "7", "1"))))

```

```{r,echo=T}
 plotda<-ggplot(final_data, aes(BodyPart,acceleration)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Acceleration on Body Part injuries ", x = "Body Part")
 plotda+coord_flip()
```

```{r,echo=T}
 ploteor<-ggplot(final_data, aes(BodyPart,aver_orient)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Direction change in orientation on Body Part injuries", x = "Body Part", y =" Direction change in orientation")
 ploteor+coord_flip()
```

```{r,echo=T}
 plotds<-ggplot(final_data, aes(severity,velocity)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of VELOCITY on severity ", x = "Severity")
 plotds+coord_flip()
```

```{r,echo=T}
 plotes<-ggplot(final_data, aes(severity,aver_dir)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Direction change in player motion on Severity", x = "Severity", y = " Direction change in player's motion")
 plotes+coord_flip()
```

```{r,echo=T}
plotsa<-ggplot(final_data, aes(severity,acceleration)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Acceleration on severity ", x = "severity")
 plotsa+coord_flip()
```


 plotso<-ggplot(final_data, aes(BodyPart,aver_orient)) + geom_boxplot(fill = "blue")+
   labs(title = "Effect of Direction change in orientation on severity", x = "severity", y =" Direction change in orientation")
 plotso+coord_flip()
```



plotpt<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = PlayType, fill = BodyPart))
 plotpt+coord_flip()+
   ggtitle("Pass play is major type related with injuries")

 plotpts<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = PlayType, fill = severity))
 plotpts+coord_flip()+
   ggtitle("Pass play has most sever injuries")

 plotpos<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = Position, fill = severity))
 plotpos+coord_flip()+
   ggtitle("Effect of Position on severity")

 plotposg<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = PositionGroup, fill = severity))
 plotposg+coord_flip()+
   ggtitle("Effect of Position Group on severity")

 plotrpos<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = RosterPosition, fill = severity))
 plotrpos+coord_flip()+
   ggtitle("Effect of Roster Position on severity")

 plotpos1<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = Position, fill = BodyPart))
 plotpos1+coord_flip()+
   ggtitle("Effect of Position on Body part injuries")

 plotposg1<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = PositionGroup, fill = BodyPart))
 plotposg1+coord_flip()+
   ggtitle("Effect of Position Group on Body part injuries")

 plotrpos1<-ggplot(data = final_data) + 
   geom_bar(mapping = aes(x = RosterPosition, fill = BodyPart))
 plotrpos1+coord_flip()+
   ggtitle("Effect of Roster Position on Body part injuries")

ggplot(final_data, aes(velocity)) + geom_histogram(binwidth = 2, fill = "blue")+
   labs(title = "Velocity vs BODY parts Histogram")+
 facet_grid(~BodyPart)

ggplot(data = injury) + 
   geom_bar(mapping = aes(x = severity, fill = severity))+
   facet_grid(~BodyPart)


#Ankle injury is most common with missed [1-7] days
#Foot injury is most common with missed [28-42] days 
#Heel injury is common only with missed [7-28] days
#Knee injury is most common with missed [7-28] days
#Toes injury is most common with missed [7-28] days



library(finalfit)
 playinj1<-as.data.frame(final_data)%>%summary_factorlist("StadiumType","BodyPart",p = F, add_dependent_label = T, cont_cut = 1)
 playinj1
 playinj2<-as.data.frame(final_data)%>%summary_factorlist("BodyPart","Weather",p = F, add_dependent_label = T, cont_cut = 1)
 playinj2
 playinj3<-as.data.frame(final_data)%>%summary_factorlist("BodyPart","PlayType",p = F, add_dependent_label = T, cont_cut = 1)
 playinj3
 playinj4<-as.data.frame(injury)%>%summary_factorlist("severity","BodyPart",p = F, add_dependent_label = T, cont_cut = 1)
 playinj4
  playinj5<-as.data.frame(final_data)%>%summary_factorlist("BodyPart","Position",p = F, add_dependent_label = T, cont_cut = 1)
 playinj5
 playinj6<-as.data.frame(final_data)%>%summary_factorlist("BodyPart","PositionGroup",p = F, add_dependent_label = T, cont_cut = 1)
 playinj6
 playinj7<-as.data.frame(final_data)%>%summary_factorlist("BodyPart","RosterPosition",p = F, add_dependent_label = T, cont_cut = 1)
 playinj7
results<-data.frame(sapply(final_data[,c(16:19,21:26)],tapply, final_data$BodyPart, function(x) {c(mean= mean(x), sd = sd(x))}))
 results
 final_data$severity<-as.numeric(final_data$severity)
 results1<-data.frame(sapply(final_data[,c(16:19,21:26)],tapply, final_data$severity, function(x) {c(mean= mean(x), sd = sd(x))}))
 results1

library(dplyr)
injury$DM_M28[injury$DM_M42==1]<-0
injury$DM_M7[injury$DM_M42==1]<-0  
injury$DM_M7[injury$DM_M28==1]<-0
injury$DM_M1[injury$DM_M42==1]<-0
injury$DM_M1[injury$DM_M28==1]<-0
injury$DM_M1[injury$DM_M7==1]<-0
model<-lm(injury$severity~injury$BodyPart+injury$Surface,data = injury)
summary(model)

#The foot injury is shown to be significant on the severity of the injury , As foot injury will be associated with increasing the length of missed days for foot-injured players.

model1<-glm(injury$DM_M1~injury$BodyPart+injury$Surface,family = "binomial")
summary(model1)
model2<-glm(injury$DM_M7~injury$BodyPart+injury$Surface,family = "binomial")
summary(model2)
model3<-glm(injury$DM_M28~injury$BodyPart+injury$Surface,family = "binomial")
summary(model3)
model4<-glm(injury$DM_M42~injury$BodyPart+injury$Surface,family = "binomial")
summary(model4)

#The above  models were carried out to specify which length of missed days due to injury would be more significant in case of foot injury.
#It can be significantly proven that the injuries in foot are associated with a length of missed days for not less than 28 days and may be lasted for more than 42 days which can be interpretted in the form of probabilities as following:
#probability of being foot-injured for more than 28 days and less than 42 days :
(exp( 2.6146 )/(1+exp( 2.6146 )))*100 = 93.18 % 
#probability of being foot-injured for 42 days or more :
(exp( 2.06723)/(1+exp(2.06723 )))*100 = 88.77 %



final_data$DM_M28[final_data$DM_M42==1]<-0
final_data$DM_M7[final_data$DM_M42==1]<-0  
final_data$DM_M7[final_data$DM_M28==1]<-0
final_data$DM_M1[final_data$DM_M42==1]<-0
final_data$DM_M1[final_data$DM_M28==1]<-0
final_data$DM_M1[final_data$DM_M7==1]<-0


library(dummies)
final_data<-cbind.data.frame(final_data,dummy(final_data$BodyPart,sep = ","))
final_data<-cbind.data.frame(final_data,dummy(final_data$StadiumType,sep = ","))
final_data<-cbind.data.frame(final_data,dummy(final_data$Surface,sep = ","))
cor(final_data$`final_data,Ankle`,final_data$velocity)
cor(final_data$`final_data,Foot`,final_data$velocity)
cor(final_data$`final_data,Knee`,final_data$velocity)
cor(final_data$`final_data,Foot`,final_data$acceleration)
cor(final_data$`final_data,Knee`,final_data$acceleration)
cor(final_data$`final_data,Ankle`,final_data$acceleration)
cor(final_data$`final_data,Foot`,final_data$vdir_ch)
cor(final_data$`final_data,Knee`,final_data$vdir_ch)
cor(final_data$`final_data,Ankle`,final_data$vdir_ch)
cor(final_data$`final_data,Foot`,final_data$accdir_ch)
cor(final_data$`final_data,Knee`,final_data$accdir_ch)
cor(final_data$`final_data,Ankle`,final_data$accdir_ch)
cor(final_data$`final_data,Foot`,final_data$aver_dir)
cor(final_data$`final_data,Knee`,final_data$aver_dir)
cor(final_data$`final_data,Ankle`,final_data$aver_dir)
cor(final_data$`final_data,Foot`,final_data$aver_orient)
cor(final_data$`final_data,Knee`,final_data$aver_orient)
cor(final_data$`final_data,Ankle`,final_data$aver_orient)
cor(final_data$`final_data,Ankle`,final_data$`final_data,Natural`)
cor(final_data$`final_data,Ankle`,final_data$`final_data,Synthetic`)
cor(final_data$`final_data,Knee`,final_data$`final_data,Natural`)
cor(final_data$`final_data,Knee`,final_data$`final_data,Synthetic`)
cor(final_data$`final_data,Foot`,final_data$`final_data,Natural`)
cor(final_data$`final_data,Foot`,final_data$`final_data,Synthetic`)
cor(final_data$`final_data,Ankle`,final_data$DM_M1)
cor(final_data$`final_data,Ankle`,final_data$DM_M7)
cor(final_data$`final_data,Ankle`,final_data$DM_M28)
cor(final_data$`final_data,Ankle`,final_data$DM_M42)
cor(final_data$`final_data,Knee`,final_data$DM_M1)
cor(final_data$`final_data,Knee`,final_data$DM_M7)
cor(final_data$`final_data,Knee`,final_data$DM_M28)
cor(final_data$`final_data,Knee`,final_data$DM_M42)
cor(final_data$`final_data,Foot`,final_data$DM_M1)
cor(final_data$`final_data,Foot`,final_data$DM_M7)
cor(final_data$`final_data,Foot`,final_data$DM_M28)
cor(final_data$`final_data,Foot`,final_data$DM_M42)
cor(final_data$`final_data,Foot`,final_data$severity)
cor(final_data$`final_data,Ankle`,final_data$severity)
cor(final_data$`final_data,Foot`,final_data$severity)
cor(final_data$`final_data,Foot`,final_data$severity)
cor(final_data$`final_data,Ankle`,final_data$severity)
cor(final_data$`final_data,Knee`,final_data$severity)
cor(final_data$severity,final_data$`final_data,dome_closed`)
cor(final_data$severity,final_data$`final_data,indoor closed`)
cor(final_data$severity,final_data$`final_data,indoor open`)
cor(final_data$severity,final_data$`final_data,outdoor`)
cor(final_data$`final_data,Foot`,final_data$`final_data,dome_closed`)
cor(final_data$`final_data,Ankle`,final_data$`final_data,dome_closed`)
cor(final_data$`final_data,Knee`,final_data$`final_data,dome_closed`)
cor(final_data$`final_data,Foot`,final_data$`final_data,indoor closed`)
cor(final_data$`final_data,Ankle`,final_data$`final_data,indoor closed`)
cor(final_data$`final_data,Knee`,final_data$`final_data,indoor closed`)
cor(final_data$`final_data,Foot`,final_data$`final_data,indoor open`)
cor(final_data$`final_data,Ankle`,final_data$`final_data,indoor open`)
cor(final_data$`final_data,Knee`,final_data$`final_data,indoor open`)
cor(final_data$`final_data,Foot`,final_data$`final_data,outdoor`)
cor(final_data$`final_data,Ankle`,final_data$`final_data,outdoor`)
cor(final_data$`final_data,Knee`,final_data$`final_data,outdoor`)
cor(final_data$`final_data,Knee`,final_data$Temperature)
cor(final_data$`final_data,Ankle`,final_data$Temperature)
cor(final_data$`final_data,Foot`,final_data$Temperature)
library(corrgram)

corrgram(final_data[,c(6:29,34)], order=NULL, panel=panel.shade, text.panel=panel.txt,
         main="Correlogram")

library(olsrr)
model<-lm(final_data$severity~final_data$RosterPosition+final_data$PlayerDay+final_data$Position+final_data$PositionGroup+final_data$StadiumType+final_data$Temperature+final_data$Weather+final_data$PlayType+final_data$PlayerGamePlay+final_data$time+final_data$velocity+final_data$acceleration+final_data$dis+final_data$aver_dir+final_data$aver_orient+final_data$vdir_ch+final_data$accdir_ch+final_data$v_dirr+final_data$acc_dirr+final_data$BodyPart+final_data$Surface,data = final_data)
ols_step_both_p(model, details=TRUE)


#Playing on a synthetic field type is associated with increasing the risk of severe long duration injuries.
#Foot injury is associated with increasing the risk of severe long duration injuries.
#Playing on a sunny weather is associated with increasing the length of missed days due to injuries occured at that weather. 
