{"cells":[{"metadata":{},"cell_type":"markdown","source":"<font size=\"+2\" color=\"blue\"><strong> NFL 1st and Future - Analytics</strong></font>"},{"metadata":{},"cell_type":"markdown","source":"![Imgur](https://i.imgur.com/wIsl8iJ.jpg)"},{"metadata":{},"cell_type":"markdown","source":"<div align=\"right\">Retrieved from <a href=\"https://www.americaninno.com/boston/every-nfl-injury-in-2013-in-one-infographic/\">here.</a></div>"},{"metadata":{},"cell_type":"markdown","source":"<div align=\"justify\"><font size=\"2\" color=\"blue\">In this report,an attempt has been made to determine the intrinsic and extrinstic factors that will contribute to lower extremity injuries. The crux of my work is to answer the question-<strong>Can you investigate the relationship between the playing surface and the injury and performance of NFL athletes?</strong>In my opinion, the above question is closely related with Bio-Mechanics. In this analysis I tried to blend the concept of Bio Mechanics with Data Sceince to have better insight.My detail analysis is explained in the following sections:<p></p>\n<ul>\n  <li>Background & Gap Analysis</li>\n  <li>Methodology</li>\n  <li>Analysis</li>\n  <ul>\n      <li>Introduction</li>\n      <li>Comparison of Natural and Synthetic Turf</li>\n      <li>Selection of Players</li>\n           <li>Selection of Players with Multiple Injuries: Synthetic Turf</li>\n      <li>Selection of Players with Multiple Injuries: Natural Turf</li>\n      <li>Common Players for Synthetic,and Natural Turf</li>\n      <li>Split Player Track Data</li> \n      </ul>    \n      <li> Player Movement Patterns and Injury </li>\n      <li>Simulation of Speed,Orientation, and Trajectory</li>\n      <li>Acceleration and Deceleration: Combining Max-Max and Max-Min Approach to Avoid Injury </li>\n      <li> How do Playing Surface, Game Scenario, Player Movement, and Weather interact to influence the risk of injury?</li>\n      <li>Selection of Optimum Threshold Value for Data Mining</li>\n      <li>Association Between Temperature and Injury </li> \n      <li>Association Between Weather and Injury</li>\n      <li>Association Between Position and Injury  </li>\n      <li>Association Between PlayType and Injury </li>\n      <li>Association Between Player Game Play and Injury</li>\n      <li>Association Between Player Day and Injury</li>\n      <li>Association Between Player Game and Injury</li>\n      <li>Association Between Stadium Type and Injury </li>\n      <li>Selection of Rules for Synthetic Turf</li>\n      </ul>\n      <li>Conclusion</li>\n      <li>Bibliography</li>\n      <li>Qualifications</li>\n    </ul> \n    </font>\n  </div>   \n       "},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong>  Background & Gap Analysis </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Earlier researchers used machine learning techniques such as random forest, decision tree, clustering, data association etc to determine possible factors behind contact injuries. Taylor et al.(2012) studied extrinsic and instric factors behind injuries. Nunes and Sousa combines data association with data clustering techniques. However, no work has been identified related to non-contact lower limb injuries. This report contains hidden factors behind the non-contact lower limb injuries."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong>  Methodology </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"I followed a very simple methodology to answer queries of the challenge. Researcher prefers not to use data mining techniques for very large data set to avoid possible rule explosions. The following steps, as shown in fig., are used to create metrics to avoid risk. "},{"metadata":{},"cell_type":"markdown","source":"![Imgur](https://i.imgur.com/Ej5wehA.jpg)"},{"metadata":{},"cell_type":"markdown","source":"I combined **Max-Max and Max-Min** approach to develop acceleration/deceleration control chart of each player who got injury and compared it with player who has no injury. "},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Analysis </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Following resources are used to understand the overall scenario:\n<ul>\n    <li> Research papers on sports analytics </li>\n    <li> Videos for NFL injuries </li>\n    <li> NFL official rules </li>\n    <li> Articles related to NFL injuries </li>\n </ul>   \nIn my opinion, one of the challenges of this competition is to handle large amount of data in a most efficient way. In this report, I have used color code. I have used golden color banner for easy detection of my research findings. I have shown findings and relevant code in step-by-step manner.  The proposed approach has elaborately explained in the figure shown below. Green box is derived data and responsible for player's injury.\n"},{"metadata":{},"cell_type":"markdown","source":"![Imgur](https://i.imgur.com/cWFSENo.jpg)"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong>  Introduction </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Synthetic Turf is more accident prone than Natural Turf due to abscence of cleats (Mack et al., 2018; Loughran et al., 2019).To verify the above claim simple exploratory data analysis is used to genrate tabular data,bar plot, and alluvial plot. In this competition three .csv files are given.I have considered subset of data from \"PlayerTrackData.csv\" for sake of simplcity and named it as \"PlayerTrackDataNew.csv\". I have used the new dataset mainly for simulation purpose.Let us study the brief contains of each .csv files."},{"metadata":{"trusted":true},"cell_type":"code","source":"options(warn=-1)\nsuppressMessages(library(tidyverse)) \nsuppressMessages(library(dplyr))\nsuppressMessages(library(ggplot2))\nsuppressMessages(library(formattable))\nsuppressMessages(library(reshape2))\nsuppressMessages(library(arules))\n#library(arulesViz)\nsuppressMessages(library(data.table))\nsuppressMessages(library(gganimate))\nsuppressMessages(library(png))\nsuppressMessages(library(grid))\nsuppressMessages(library(ggcorrplot))\nsuppressMessages(library(GoodmanKruskal))\n#suppressMessages(library(ggalluvial))\nlist.files(path = \"../input\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:white\"><font size=\"3\" color=\"steelblue\"><strong> Load Data </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"<div align=\"left\"> Deatil description of each data set is given <a href=\"https://www.kaggle.com/c/nfl-playing-surface-analytics/data\">here </a> except Ankle-Nat, and comp-noinj-inj-syn.csv</div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"NFL <- read.csv(\"../input/nfl-playing-surface-analytics/InjuryRecord.csv\")\nplayertrackorg<- fread(\"../input/nfl-playing-surface-analytics/PlayerTrackData.csv\")\nplayertrack <- read.csv(\"../input/playertrackdataanim/comp-noinj-inj-syn.csv\")\nNFL.PlayList <- read.csv(\"../input/nfl-playing-surface-analytics/PlayList.csv\")\ndata.nat_syn <- read.csv(\"../input/anklenat/Ankle-Nat.csv\")\ncat(paste(\"No. of variables:\",length(NFL),\"and number of rows: \",nrow(NFL),\"in InjuryRecord.csv\\n\"))\ncat(paste(\"No. of variables:\",length(NFL.PlayList),\"and number of rows: \",nrow(NFL.PlayList),\"in PlayList.csv\\n\"))\ncat(paste(\"No. of variables:\",length(playertrackorg),\"and number of rows: \",nrow(playertrackorg),\"in PlayerTrackData.csv\\n\\n\"))\ncat(paste(\"No. of variables:\",length(playertrack),\"and number of rows: \",nrow(playertrack),\"in comp-noinj-inj-syn.csv\\n\"))\ncat(paste(\"No. of variables:\",length(data.nat_syn),\"and number of rows: \",nrow(data.nat_syn),\"in Ankle-Nat.csv\\n\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Comparison of Natural and Synthetic Turf </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"NFL.Syn<-NFL %>% filter(Surface==\"Synthetic\") %>% arrange(BodyPart) %>% count(BodyPart)\nNFL.Nat<-NFL %>% filter(Surface==\"Natural\") %>% arrange(BodyPart) %>% count(BodyPart)\ndatacomp <- data.frame(matrix(nrow=1,ncol=8))\ncolnames(datacomp) <- c(\"Name\",\"Ankle\",\"Foot\",\"Heel\",\"Knee\",\"Toes\",\"Avg\",\"Std\")\nprocdata <- function()\n{\n  if(nrow(NFL.Nat) > nrow(NFL.Syn))\n  {\n    df <- !(NFL.Nat$BodyPart %in% NFL.Syn$BodyPart)\n    ind = 1\n    for(i in c(1:length(df)))\n    {\n      if(as.character(df[i])==\"TRUE\")\n        {NFL.Syn[nrow(NFL.Syn)+ind,]=c(as.character(NFL.Nat$BodyPart[i]),as.numeric(0))\n        ind=ind+1\n      }\n    }\n    df<-merge(x=NFL.Nat,y=NFL.Syn,by=\"BodyPart\",all=TRUE)\n    return(df)\n    \n  }else\n  {\n    df <- !(NFL.Syn$BodyPart %in% NFL.Nat$BodyPart)\n    ind = 1\n    for(i in c(1:length(df)))\n    {\n      if(as.character(df[i])==\"TRUE\")\n      {NFL.Nat[nrow(NFL.Nat)+ind,]=c(as.character(NFL.Syn$BodyPart[i]),as.numeric(0))\n      ind=ind+1\n      }\n    }\n    df<-merge(x=NFL.Nat,y=NFL.Syn,by=\"BodyPart\",all=TRUE)\n    return(df)\n  }\n}\n\ndf<- procdata()\ncolnames(df)<-c(\"BodyPart\",\"Natural\",\"Synthetic\")\n\ndf <- df %>% mutate('%-Change'= round((as.numeric(df$Synthetic)-as.numeric(df$Natural))/as.numeric(df$Natural)*100,2))\ncGreen = \"#DeF7E9\"\nGreen = \"#71CA97\"\ncRed = \"#ff7f7f\"\ncCol1=\"#00AFBB\"\ncCol2=\"#E7B800\"\npercent_format <-formatter(\"span\",\n                           style= x ~ style(font.weight=\"bold\",\n                           color=ifelse(x > 0,Green,ifelse(x < 0,cRed,\"black\"))),\n                            x ~ icontext(ifelse(x > 0,\"arrow-up\",ifelse(x < 0,\"arrow-down\",\"\")),x))\nformattable(df,align=c(\"l\",\"c\",\"c\",\"r\"),list('Name'=formatter(\"span\",style=~style(color=\"grey\",font.weight=\"bold\")),\n                                                             'BodyPart'=color_tile(cGreen,Green),\n                                                             'Natural'= color_tile(cGreen,Green),\n                                                             'Synthetic'= color_tile(cGreen,Green),\n                                                             '%-Change' = percent_format  \n                                                             ))\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Result confirms the higher rate of injury on Synthetic Turf. Result  substantiates claim of Mack et al., 2018, and Loughran et al., 2019"},{"metadata":{"trusted":true},"cell_type":"code","source":"df2<-as.data.frame(matrix(nrow=1,ncol=6))\ncolnames(df2) <- c(\"Name\",\"Ankle\",\"Foot\",\"Heel\",\"Knee\",\"Toes\")\ndf2[\"Name\"] <- \"Natural\"\ndf2[1,2:6] <- as.numeric(df$Natural)\ndf2[2,1] <- \"Synthetic\"\ndf2[2,2:6] <- as.numeric(df$Synthetic)\ndf2.plot<-melt(df2,id.vars = \"Name\")\nTurf_name <- df2.plot$Name\nggplot(df2.plot,aes(x=variable,y=value,fill=Turf_name))+geom_bar(stat=\"identity\",position=\"dodge\")+\n  scale_color_manual(values=c(\"#00AFBB\",\"#E7B800\"))+\n  scale_fill_manual(values=c(\"#00AFBB\",\"#E7B800\"))+theme_classic()+\n  labs(x=\"BodyPart\",y=\"Number of injury\")\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"On **Synthetic Turf players are having more Ankle, and Toe injury comparing to Natural Turf**. On both turf knee injuries are same. However, **Synthetic Turf has lower foot injury**. No record for heel injury on Synthetic Turf. Let us try to find reason behind Ankle,Knee, and Toe injuries."},{"metadata":{"trusted":true},"cell_type":"code","source":"injury_effect <-function(data)\n{\n  c<-c()\n  A<-colnames(data[6:9])\n  for (i in 1:length(A))\n  {\n    c[i] <- as.numeric(substr(A[i],5,str_length(A[i])))\n  }\n  result <- as.data.frame(matrix(nrow=nrow(data),ncol=3))\n  colnames(result) <- c(\"Surface\",\"BodyPart\",\"Severity\")\n  temp_sev <- rowSums(c*data[6:9])\n  result$Severity <- ifelse(temp_sev==78,\"Very Critical Injury\",\n                            ifelse(temp_sev==36,\"Critical Injury\",\n                             ifelse(temp_sev==8,\"Moderate Injury\",\"Normal Injury\")))\n  result$Surface <- data$Surface\n  result$BodyPart <- data$BodyPart\n  temp <- count(result,Surface,BodyPart,Severity)\n  return(temp)\n}\n\nNFL.alluv <- injury_effect(NFL)\ncolnames(NFL.alluv) <- c(\"Surface\",\"BodyPart\",\"Severity\",\"Freq\")\nb1 <- ggplot(as.data.frame(NFL.alluv),\n       aes(y =Freq, axis1 =Surface, axis2 = BodyPart)) +\n  geom_alluvium(aes(fill = Severity), width = 1/12) +\n  geom_stratum(width = 1/12, fill = \"black\", color = \"grey\") +\n  geom_label(stat = \"stratum\", infer.label = TRUE) +\n  scale_x_discrete(limits = c(\"Surface\",\"BodyPart\"), expand = c(.05, .05)) +\n  scale_fill_brewer(type = \"qual\", palette = \"Set1\") +\n  ggtitle(\"NFL-INJURIES\")\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"![Imgur](https://i.imgur.com/FlvYScL.png)"},{"metadata":{},"cell_type":"markdown","source":"The calculation is based on assumption that field \"DM_M1\" refers the number of days a player has to take rest due to injury. A weighted sum is further calculated. **Four different linguistic variables are considered -normal,moderate,critical, and very critical to discretize weighted sum**."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Selection of Players </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"It has been categorically mentioned that participants are not required to develop a predictive model. It isn't a traditional supervised Kaggle machine learning competition. In my opinion, selection of players is very important part of the challenge. "},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Selection of Players with Multiple Injuries: Synthetic Turf </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"As part of this challenge, the NFL has provided full player tracking of on-field position for 250 players over two regular season schedules. One hundred of the athletes in the study data set sustained one or more injuries during the study period that were identified as a non-contact injury of a type that may have turf interaction as a contributing factor to injury. The remaining 150 athletes serve as a representative sample of the larger NFL population that did not sustain a non-contact lower-limb injury during the study period. Let us study the problem statement. We need to find 100 common players from \"PlayerTrackData.csv\" and \"InjuryRecord.csv\". "},{"metadata":{"trusted":true},"cell_type":"code","source":"matching_players <- function(playertrackorg,NFL)\n    {\n    macthing_lst <- c()\n    temp<- substr(unique(playertrackorg$PlayKey),1,5)\n    matching_lst <- intersect(NFL$PlayerKey,unique(temp))\n    return(matching_lst)\n}\n\nmatching_lst <- data.frame(\"PlayerKey\"=matching_players(playertrackorg,NFL))\ncat(paste(\"No. of Players those who have injury and included in PlayerTrackData : \",nrow(matching_lst),\"\\n\"))\ncat(paste(\"PlayerKey:\",matching_lst$PlayerKey))\nNFL.Syn <- NFL %>% filter(Surface==\"Synthetic\")\nNFL.Syn <- data.frame(NFL.Syn)\nmatching_lst.Syn <- data.frame(\"PlayerKey\"=intersect(NFL.Syn$PlayerKey,matching_lst$PlayerKey))\nNFL.Syn.matching <- data.frame(NFL.Syn[NFL.Syn$PlayerKey %in% matching_lst.Syn$PlayerKey,])\ncat(paste(\"\\n\\nNumber of Players Selected from Synthetic Turf: \",nrow(NFL.Syn.matching), \"to prepare PlayerTrackData\\n\"))\nNFL.Syn.matching.dup <- data.frame(NFL.Syn.matching[duplicated(NFL.Syn.matching$PlayerKey),])\ncolnames(NFL.Syn.matching.dup) <- c(\"PlayerKey\")\ncat(paste(\"Number of Players with Multiple Injuries on Synthetic Turf: \",nrow(NFL.Syn.matching.dup ),\" is in PlayerTrackData\\n\"))\ncat(paste(\"Player with Multiple Injuries on Synthetic Turf,Player Key:\",NFL.Syn.matching.dup$PlayerKey))\n##NFL.Syn.dup.details <- NFL.Syn.matching %>% filter(PlayerKey==NFL.Syn.matching.dup$PlayerKey)\nNFL.Syn.matching[NFL.Syn.matching$PlayerKey %in% NFL.Syn.matching.dup$PlayerKey, ]\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Selection of Players with Multiple Injuries: Natural Turf </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"NFL.Nat <- NFL %>% filter(Surface==\"Natural\")\nNFL.Nat <- data.frame(NFL.Nat)\nmatching_lst.Nat <- data.frame(\"PlayerKey\"=intersect(NFL.Nat$PlayerKey,matching_lst$PlayerKey))\nNFL.Nat.matching <- data.frame(NFL.Nat[NFL.Nat$PlayerKey %in% matching_lst.Nat$PlayerKey,])\ncat(paste(\"\\n\\nNumber of Players Selected from Natural Turf: \",nrow(NFL.Nat.matching), \"to prepare PlayerTrackData\\n\"))\nNFL.Nat.matching.dup <- data.frame(NFL.Nat.matching[duplicated(NFL.Nat.matching$PlayerKey),])\ncolnames(NFL.Nat.matching.dup) <-c(\"PlayerKey\")\ncat(paste(\"Number of Players with Multiple Injuries on Natural Turf: \",nrow(NFL.Nat.matching.dup ),\" is in PlayerTrackData\\n\"))\ncat(paste(\"Players with Multiple Injuries on Natural Turf,Player Key:\",NFL.Nat.matching.dup$PlayerKey,\"\\n\"))\n#NFL.Nat.dup.details <- NFL.Nat.matching %>% filter(PlayerKey==NFL.Nat.matching.dup$PlayerKey)\nNFL.Nat.matching[NFL.Nat.matching$PlayerKey %in% NFL.Nat.matching.dup$PlayerKey, ]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Common Players for Synthetic,and Natural Turf </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"common <- data.frame(intersect(NFL.Nat.matching$PlayerKey,NFL.Syn.matching$PlayerKey))\ncolnames(common) <- c(\"PlayerKey\")\nNFL.Nat.matching[NFL.Nat.matching$PlayerKey %in% common$PlayerKey,]\nNFL.Syn.matching[NFL.Syn.matching$PlayerKey %in% common$PlayerKey,]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Obtained result substantiates the above problem statement.It is pertinent to mention that \"PlayKey\" is unique key of \"PlayerTrackData.csv\" but lot of missing values are present in \"Injury.csv\". Hence by using \"PlayKey\" we can expect to get only 76 players not 100. \"Injury.csv\" has 105 rows, 5 pairs of duplicate PlayerKey i.e 10. Hence, unique values are (105-10)+5=100."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Split Player Track Data </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"I have splitted large PlayerTrackData.csv as per the Play Key of the above selected players. Data size is between 12 Mb - 35 Mb. Below code we can use to split data sequentially. "},{"metadata":{"trusted":true},"cell_type":"code","source":"temp<-NULL\ntemp<-playertrackorg[playertrackorg$PlayKey %like% \"38192\",]\nwrite.csv(file=\"38192.csv\",temp)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong>Selection of Features for Data Mining </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Let us consider three linguistic terms, namely, \"Synthetic Turf\", \"Dome Type Stadium\",and \"Indoors Weather\" together to study player 47307. He has both Knee and Ankle injury. One of the challenge of the competition is to deal with about 4 GB PlayerTrackData.csv. I have considered a subset of the PlayerTrackData.csv to implement Data Mining Technique as rule explotion is quite expected for such considerable amount of data.    "},{"metadata":{"_uuid":"1873a100-cb5b-439f-b12b-4c89cd7210ae","_cell_guid":"1a83a2b5-75e8-4eb7-8337-99a27af646cf","trusted":true},"cell_type":"code","source":"#NFL.PlayList$StadiumType <- as.character(NFL.PlayList$StadiumType)\n#NFL.PlayList$PlayType <- as.character(NFL.PlayList$PlayType)\n#NFL.PlayList$Weather <- as.character(NFL.PlayList$Weather)\n#NFL.PlayList$Position <-as.character(NFL.PlayList$Position)\n#NFL.PlayList$PositionGroup <- as.character(NFL.PlayList$PositionGroup)\nNFL.PlayList <- NFL.PlayList %>% filter(Position!=\"Missing Data\")\nNFL.PlayList <- NFL.PlayList %>% filter(PositionGroup!=\"Missing Data\")\nNFL.PlayList <- NFL.PlayList %>% filter(Temperature > -999)\nNFL.PlayList <- NFL.PlayList %>% filter(Weather != \"\" || Weather !=\"0\" || Weather != \"N/A(Indoors)\")\nNFL.PlayList <- NFL.PlayList %>% filter(StadiumType != \"\")\nNFL.PlayList <- NFL.PlayList %>% filter(PlayerDay > 0)\nNFL.PlayList <- NFL.PlayList %>% filter(PlayerGame > 0)\n#NFL.PlayList$StadiumType <- as.character(NFL.PlayList$StadiumType)\n#NFL.PlayList <- NFL.PlayList %>% filter(StadiumType != \" \")\nNFL.PlayList.Syn <- NFL.PlayList %>% filter(FieldType==\"Synthetic\")\nNFL.PlayList.Syn.Indoors <- NFL.PlayList.Syn %>% filter(Weather==\"Indoors\")\nNFL.PlayList.Syn.Indoors.Dome <- NFL.PlayList.Syn.Indoors %>% filter(StadiumType==\"Dome\")\nNFL.PlayList.Syn.Indoors.Dome.Injury <- merge(x=NFL,y=NFL.PlayList.Syn.Indoors.Dome,by=\"PlayKey\",all=TRUE)\nNFL.Temp.Injury <- NFL.PlayList.Syn.Indoors.Dome.Injury  %>% select(c(\"PlayKey\",\"FieldType\",\"StadiumType\",\"RosterPosition\",\"PlayType\",\n                                                 \"BodyPart\",\"PlayerGamePlay\",\n                                                 \"Position\",\"PositionGroup\",\"PlayerDay\",\"PlayerGame\"))\ntempplayertrack <- playertrackorg[playertrackorg$PlayKey %in% NFL.PlayList.Syn.Indoors.Dome$PlayKey,]\n\ncat(paste(\"Retrieving \",nrow(tempplayertrack),\" rows from PlayerTrackData.csv for Synthetic Turf, Dome Type Stadium,and Indoors Weather\\n\"))\ncat(paste(\"Above \",nrow(tempplayertrack),\"rows contain player with no injury or atleast one injury\\n\"))\nNFL.Injury.PlayList.PlayerTrackData <- merge(x=NFL.Temp.Injury,y=tempplayertrack,by=\"PlayKey\",all=TRUE)\ncat(paste(\"After merging 3 Data Set \",nrow(tempplayertrack),\"rows are generated for Synthetic Turf,Dome Type Stadium, and Indoors Weather\\n\"))\nNFL.Injury.PlayList.PlayerTrackData <- na.omit(NFL.Injury.PlayList.PlayerTrackData)\nwrite.csv(file=\"Injury-PlayList-PlayerTrackData.csv\",NFL.Injury.PlayList.PlayerTrackData)\ntemp <- NFL.Injury.PlayList.PlayerTrackData %>% select(c(\"RosterPosition\",\"PlayType\",\n         \"BodyPart\",\"PlayerGamePlay\",\"Position\",\"PositionGroup\",\n         \"PlayerDay\",\"PlayerGame\",\"time\",\"event\",\"x\",\"y\",\n         \"dir\",\"dis\",\"o\",\"s\"))\n\nNFL.Temp.Injury.Syn.Tau <- GKtauDataframe(temp)\nplot(NFL.Temp.Injury.Syn.Tau,title=\"Synthetic Turf|Dome Type Stadium|Indoors Weather\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(temp$RosterPosition,temp$BodyPart)\nGKtau(temp$PlayType,temp$BodyPart)\nGKtau(temp$RosterPosition,temp$BodyPart)\nGKtau(temp$PlayerGamePlay,temp$BodyPart)\nGKtau(temp$Position,temp$BodyPart)\nGKtau(temp$PositionGroup,temp$BodyPart)\nGKtau(temp$PlayerDay,temp$BodyPart)\nGKtau(temp$PlayerGame,temp$BodyPart)\nGKtau(temp$time,temp$BodyPart)\nGKtau(temp$event,temp$BodyPart)\nGKtau(temp$x,temp$BodyPart)\nGKtau(temp$y,temp$BodyPart)\nGKtau(temp$dir,temp$BodyPart)\nGKtau(temp$dis,temp$BodyPart)\nGKtau(temp$o,temp$BodyPart)\nGKtau(temp$s,temp$BodyPart)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"In the above analysis, Goodman Kruskal Tau is used to find association between categorical and numerical values. Traditional corrplot is used to find association between numeric values. Tau Value shows that \"PlayerGamePlay\",\"Position\",\"PositionGroup\",\"PlayerDay\",\"PlayerGame\",\"time\",\"event\",\"x\",\"y\",\"dir\",\"dis\",\"o\",and \"s\" has no association with \"BodyPart\"."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Player Movement Patterns and Injury </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"The purpose of this challenge is to determine factors for non-contact lower-limb injury to determine novel metrics that characterize player movement on the field:\n<ul>\n    <li> Speed </li>\n    <li> Directional changes </li>\n    <li> Acceleration/Deceleration </li>\n    <li> Distance </li>\n</ul>    \nAbove four parameters re-affirmed that challenge is related to Gait that is the pattern of movement of player, Vector Mechanics, and Bio Mechanics.A simple simulation study is considered to assey the above objective."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Simulation of Speed,Orientation, and Trajectory </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Let us consider player 47307,27363,and 33474. 47307 got Knee and Ankle injury and he played 47307-10-18 (Game Id). All three players played in Dome Type Stadium, Indoors Weather, and Synthetic Turf. Last two players had no injury."},{"metadata":{},"cell_type":"markdown","source":"Animated Speed-Time Plot [Click here](https://i.imgur.com/oSOPhac.gifv)"},{"metadata":{},"cell_type":"markdown","source":"Animated Orientation-Time Plot [Click here](https://i.imgur.com/curU7Cd.gifv)"},{"metadata":{},"cell_type":"markdown","source":"Animated Distance-Time Plot [Click here](https://i.imgur.com/lP3qZ5Q.gifv)"},{"metadata":{},"cell_type":"markdown","source":"Animated Direction-Time Plot [Click here](https://i.imgur.com/MS7rAxk.gifv)"},{"metadata":{},"cell_type":"markdown","source":"Animated Trajectory [Click here](https://i.imgur.com/dc6GCME.gifv)"},{"metadata":{"trusted":true},"cell_type":"code","source":"temp.47307 <- playertrack %>% filter(PlayKey == \"47307-10-18\")\n   temp.27363 <- playertrack %>% filter(PlayKey == \"27363-10-18\")\n   temp.33474 <- playertrack %>% filter(PlayKey == \"33474-10-18\")\n   df <- as.data.frame(matrix(nrow=3,ncol=5))\n   colnames(df) <- c(\"PlayKey\",\"Speed\",\"Distance\",\"Orientation\",\"Direction\")\n   df$PlayKey <- c(\"27363-10-18\",\"33474-10-18\",\"47307-10-18\")\n   df$Speed <- c(mean(20*temp.27363$s),mean(20*temp.33474$s),mean(20*temp.47307$s))\n   df$Distance <-c(mean(20*temp.27363$dis),mean(20*temp.33474$dis),mean(20*temp.47307$dis))\n   df$Orientation <-c(mean(temp.27363$o),mean(temp.33474$o),mean(temp.47307$o))\n   df$Direction <- c(mean(temp.27363$dir),mean(temp.33474$dir),mean(temp.47307$dir))\n   df.plot<-melt(df,id.vars = \"PlayKey\")\n   Play_Key <- df.plot$PlayKey\n   ggplot(df.plot,aes(x=variable,y=value,fill=Play_Key))+geom_bar(stat=\"identity\",position=\"dodge\")+\n     scale_color_manual(values=c(\"#71CA97\",\"#00AFBB\",\"#E7B800\"))+\n     scale_fill_manual(values=c(\"#71CA97\",\"#00AFBB\",\"#E7B800\"))+theme_bw()+\n     labs(x=\"Player Track Data\",y=\"Mean\")\n   \n   df3 <- as.data.frame(matrix(nrow=3,ncol=5))\n   colnames(df3) <- c(\"PlayKey\",\"Speed\",\"Distance\",\"Orientation\",\"Direction\")\n   df3$PlayKey <- c(\"27363-10-18\",\"33474-10-18\",\"47307-10-18\")\n   df3$Speed <- c(max(20*temp.27363$s),max(20*temp.33474$s),max(20*temp.47307$s))\n   df3$Distance <-c(max(20*temp.27363$dis),max(20*temp.33474$dis),max(20*temp.47307$dis))\n   df3$Orientation <-c(max(temp.27363$o),max(temp.33474$o),max(temp.47307$o))\n   df3$Direction <- c(max(temp.27363$dir),max(temp.33474$dir),max(temp.47307$dir))\n   df3.plot<-melt(df3,id.vars = \"PlayKey\")\n   Play_Key <- df3.plot$PlayKey\n   ggplot(df3.plot,aes(x=variable,y=value,fill=Play_Key))+geom_bar(stat=\"identity\",position=\"dodge\")+\n     scale_color_manual(values=c(\"#FFDB6D\",\"#C4961A\",\"#F4EDCA\"))+\n     scale_fill_manual(values=c(\"#FFDB6D\",\"#C4961A\",\"#F4EDCA\"))+theme_bw()+\n     labs(x=\"Player Track Data\",y=\"Max\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The above plot shows clearly that max and mean of speed,distance,orientation, and direction of player 47307 is not more than player 27363,and 33474**. Scale factor 20 is used for Speed and Distance field."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Acceleration and Deceleration: Combining Max-Max and Max-Min Approach to Avoid Injury </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Speed is a scalar quantity. Given unit is in Yard/Sec. Hence, it's first derivative will give magnitude of acceleration. In this study, I have considered case of player 47307,PlayKey-47307-10-18,Dome Type Stadium,Indoors Weather, and Synthetic Turf. Player 47307 got Ankle and Knee injury. 2 players are also considered - player 27363, and player 33474 and both of them got no injury. **Why player 47307 got inury?** I measure the area under speed-time, and distance-time curve of all three. Inquisitve reader can try library(MESS) to measure auc. Unfortunately, auc of 27363 is not higher then any of the above two players. However, the peak vaue of acceleration/deceleration of player 47307 is much higher than player27363, and 33474.The average weight of NFL players is 245.86 pounds with a bound of 2.556. If we multiple the mass with the peak value of acceleration and/deceleration then we can determine the magnitude of force. Try to anticipate its magnitude. I have further considered two limits - upper limit and lower limit. \n<ul>\n    <li> Upper Limit = Max(max(acceleration of 27363),max(acceleration of 33474))</li>\n    <li> Lower Limit = Max(min(acceleration of 27363),min(acceleration of 33474))</li>\n</ul>\nRemeber acceleration and deceleration has opposite sign.Max(deceleration of 27363) is the Min(acceleration of 27363).Thus, combination of **Max-Max, and Max-Min** is justified.Player 47307 got injury as his acceleration and deceleration crossed the upper and lower limit. In the below figure, I have shown linear acceleration. Actual acceleration of player 47307 is resultant of two accelerations. One of them is linear acceleration.However, increase of one component will increase resultant."},{"metadata":{"trusted":true},"cell_type":"code","source":"# retrieving from processed data - not given dataset\ndata.47307 <- playertrack %>% filter(PlayKey==\"47307-10-18\")\ndata.27363 <- playertrack %>% filter(PlayKey==\"27363-10-18\")\ndata.33474 <- playertrack %>% filter(PlayKey==\"33474-10-18\")\n\nacc.47307 <- as.data.frame(matrix(nrow=nrow(data.47307)-1,ncol=2))\ncolnames(acc.47307) <- c(\"time\",\"acc\")\nacc.27363 <- as.data.frame(matrix(nrow=nrow(data.27363)-1,ncol=2))\ncolnames(acc.27363) <- c(\"time\",\"acc\")\nacc.33474 <- as.data.frame(matrix(nrow=nrow(data.33474)-1,ncol=2))\ncolnames(acc.33474) <- c(\"time\",\"acc\")\n\nacc.47307$time <- data.47307$time[2:nrow(data.47307)]\nacc.27363$time <- data.27363$time[2:nrow(data.27363)]\nacc.33474$time <- data.33474$time[2:nrow(data.33474)]\n\nacc.47307$acc<- diff(data.47307$s)/diff(data.47307$time)\nacc.27363$acc<- diff(data.27363$s)/diff(data.27363$time)\nacc.33474$acc <- diff(data.33474$s)/diff(data.33474$time)\n\ndf <- merge(acc.47307,acc.33474,by=\"time\",all=TRUE)\ntemp <- merge(df,acc.27363,by=\"time\",all=TRUE)\ncolnames(temp)<-c(\"Time\",\"acc_47307\",\"acc_33474\",\"acc_27363\")\n\nplayerkey <- c(\"47307-10-18\",\"27363-10-18\",\"33474-10-18\")\nggplot(temp,aes(x=Time))+geom_line(aes(y=acc_47307,color=\"47307-10-18\"))+\n      geom_point(aes(y=acc_47307,color=\"47307-10-18\"))+\n      geom_line(aes(y=acc_33474,color=\"33474-10-18\"))+\n      geom_point(aes(y=acc_33474,color=\"33474-10-18\"),alpha=0.7)+\n      geom_line(aes(y=acc_27363,color=\"27363-10-18\"))+\n      geom_point(aes(y=acc_27363,color=\"27363-10-18\"),alpha=0.5)+\n      geom_hline(yintercept =max(max(acc.33474$acc),max(acc.27363$acc)),linetype=\"dashed\",color=\"red\",size=1)+\n      geom_hline(yintercept =min(min(acc.33474$acc),min(acc.27363$acc)),linetype=\"dashed\",color=\"red\",size=1)+\n      labs(x=\"Time(Sec)\",y=\"Acceleration/Deceleration(Yard/Sec^2)\")+\n      theme_classic()\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong>How do Playing Surface, Game Scenario, Player Movement, and Weather interact to influence the risk of injury?</strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"data.435407 <- data.nat_syn %>% filter(PlayKey==\"43540-7-2\")\ndata.435403 <- data.nat_syn %>% filter(PlayKey==\"43540-3-14\")\ndata.44449 <- data.nat_syn %>% filter(PlayKey==\"44449-6-13\")\ndata.45950 <- data.nat_syn %>% filter(PlayKey==\"45950-8-18\")\n\nacc.435407 <- as.data.frame(matrix(nrow=nrow(data.435407)-1,ncol=2))\ncolnames(acc.435407) <- c(\"time\",\"acc\")\nacc.435403 <- as.data.frame(matrix(nrow=nrow(data.435403)-1,ncol=2))\ncolnames(acc.435403) <- c(\"time\",\"acc\")\nacc.44449 <- as.data.frame(matrix(nrow=nrow(data.44449)-1,ncol=2))\ncolnames(acc.44449) <- c(\"time\",\"acc\")\nacc.45950 <- as.data.frame(matrix(nrow=nrow(data.45950)-1,ncol=2))\ncolnames(acc.45950) <- c(\"time\",\"acc\")\n\nacc.435407$time <- data.435407$time[2:nrow(data.435407)]\nacc.435403$time <- data.435403$time[2:nrow(data.435403)]\nacc.44449$time <- data.44449$time[2:nrow(data.44449)]\nacc.45950$time <- data.45950$time[2:nrow(data.45950)]\n\nacc.435407$acc<- diff(data.435407$s)/diff(data.435407$time)\nacc.435403$acc<- diff(data.435403$s)/diff(data.435403$time)\nacc.44449$acc <- diff(data.44449$s)/diff(data.44449$time)\nacc.45950$acc <- diff(data.45950$s)/diff(data.45950$time)\n\ndf <- merge(acc.435407,acc.435403,by=\"time\",all=TRUE)\ndf2 <- merge(df,acc.44449,by=\"time\",all=TRUE)\ncolnames(df2)<-c(\"time\",\"acc_43540_7\",\"acc_43540_3\",\"acc_44449\")\ntemp <- merge(df2,acc.45950,by=\"time\",all=TRUE)\ncolnames(temp)<-c(\"Time\",\"acc_43540_7\",\"acc_43540_3\",\"acc_44449\",\"acc_45950\")\n\n\np<-ggplot(temp,aes(x=Time))+geom_line(aes(y=temp$acc_43540_7,color=\"43540-7-2:Cloudy:72:MLB-Pass\"))+\n  geom_point(aes(y=temp$acc_43540_7,color=\"43540-7-2:Cloudy:72:MLB-Pass\"))+\n  geom_line(aes(y=temp$acc_43540_3,color=\"43540-3-14:Sunny:89:MLB-Pass\"))+\n  geom_point(aes(y=temp$acc_43540_3,color=\"43540-3-14:Sunny:89:MLB-Pass\"))+\n  geom_line(aes(y=temp$acc_44449,color=\"44449-6-13:Rain:52:WR-Pass\"))+\n  geom_point(aes(y=temp$acc_44449,color=\"44449-6-13:Rain:52:WR-Pass\"))+\n  geom_line(aes(y=temp$acc_45950,color=\"45950-8-18:Cold:38:FS-Punt\"))+\n  geom_point(aes(y=temp$acc_45950,color=\"45950-8-18:Cold:38:FS-Punt\"))+\n  geom_hline(yintercept = max(acc.435403$acc),linetype=\"dashed\",color=\"red\",size=1)+\n  annotate(geom=\"text\",x=40,y=max(acc.435403$acc)+.2,label=paste(\"43540-3-14|Max Acc:\",round(max(acc.435403$acc),3)),color=\"black\",size=3,fontface=\"bold\")+\n  geom_hline(yintercept = min(acc.435403$acc),linetype=\"dashed\",color=\"red\",size=1)+\n  annotate(geom=\"text\",x=40,y=min(acc.435403$acc)-.2,label=paste(\"43540-3-14|Min Acc:\",round(min(acc.435403$acc),3)),color=\"black\",size=3,fontface=\"bold\")+\n  geom_hline(yintercept = max(acc.44449$acc),linetype=\"dashed\",color=\"red\",size=1)+\n  annotate(geom=\"text\",x=40,y=max(acc.44449$acc)+.2,label=paste(\"44449-6-13|Max Acc:\",round(max(acc.44449$acc),3)),color=\"black\",size=3,fontface=\"bold\")+\n  geom_hline(yintercept = min(acc.44449$acc),linetype=\"dashed\",color=\"red\",size=1)+\n  annotate(geom=\"text\",x=40,y=min(acc.44449$acc)-.2,label=paste(\"44449-6-13|Min Acc:\",round(min(acc.44449$acc),3)),color=\"black\",size=3,fontface=\"bold\")+\n  labs(x=\"Time(Sec)\",y=\"Acceleration/Decceleration(Yard/Sec^2)\",title=\"Natural Turf-Outdoor Stadium\",subtitle=\"Ankle Injury\")+\n  theme_classic()\n\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"![Imgur](https://i.imgur.com/ohxGldg.png)"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Selection of Optimum Threshold Value for Data Mining </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"In the above study, I have considered a subset of large dataset. The following paramerts are considered to group data for player 47307:\n<ul>\n    <li> Surface Type (i.e.Synthetic)</li>\n    <li> Stadium Type (i.e.Dome Shape)</li>\n    <li> Weather (i.e. indoors) </li>\n </ul>\n \n Let us use apriori to find association between surface type,stadium type,weather,bodypart injuries etc."},{"metadata":{"trusted":true},"cell_type":"code","source":"NFL.Temp.Injury <- merge(x=NFL,y=NFL.PlayList,by=\"PlayKey\",all=TRUE)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury %>% filter(Surface==\"Synthetic\")\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% select(c(\"StadiumType\",\"Weather\",\"Position\",\"PlayerGame\",\"PlayType\",\"PlayerGamePlay\",\"PlayerDay\",\"Temperature\",\"BodyPart\"))\nNFL.Temp.Injury.Syn$StadiumType <- as.factor(NFL.Temp.Injury.Syn$StadiumType)\nNFL.Temp.Injury.Syn$Weather <- as.factor(NFL.Temp.Injury.Syn$Weather)\nNFL.Temp.Injury.Syn$BodyPart <- as.factor(NFL.Temp.Injury.Syn$BodyPart)\nNFL.Temp.Injury.Syn$Position <- as.factor(NFL.Temp.Injury.Syn$Position)\nNFL.Temp.Injury.Syn$PlayType <- as.factor(NFL.Temp.Injury.Syn$PlayType)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(PlayerDay >0)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(Temperature > -999)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(PlayerGame > 0)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(Weather != \"\" || Weather !=\"0\" || Weather != \"N/A(Indoors)\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Temperature and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$Temperature,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Above Tau value confirms that temperature is one of the parameters to be used to predict occurance of injury.**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Weather and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$Weather,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Weather can be used to predict occurance of any injury.**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Position and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$Position,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Position can be used to predict occurance of injury**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between PlayType and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$PlayType,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**PlayType can be used for prediction of injury**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Player Game Play and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$PlayerGamePlay,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Player Game Play can be used to predict occurance of injuries**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Player Day and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$PlayerDay,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Player Day can be used to predict the occurance of any injury**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Player Game and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$PlayerGame,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Player Game can be used to predict the occurance of any injury**"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:#ffd700\"><font size=\"3\" color=\"black\"><strong> Association Between Stadium Type and Injury </strong></font></div>"},{"metadata":{"trusted":true},"cell_type":"code","source":"GKtau(NFL.Temp.Injury.Syn$StadiumType,NFL.Temp.Injury.Syn$BodyPart)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"NFL.Temp.Injury.Syn.Tau <- GKtauDataframe(NFL.Temp.Injury.Syn)\nplot(NFL.Temp.Injury.Syn.Tau,title=\"Synthetic Turf|Dome Type Stadium|Indoors Weather:Without PlayerTrack\")\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Temperature is one of the parameter of weather. Often too much humidity in air spoil performance of players. Therefore weather should be a factor to influence injury. Stadium Type can also influence temperature. For instance, temperature can be controlled in indoor temperature. Stadium Type,thus, should be selected. Change of dataset will positively change Tau value. I have seen change of value for field PlayType from 0.256 to NaN. Position changes from 0.291 to NaN. Weather changes from 0.578 to NaN.Stadium Type changes from 0.292 to NaN. Hence, association will change due to change of backend data.Let us generate rule based on present dataset."},{"metadata":{"trusted":true},"cell_type":"code","source":"cat(\"Selecting optimum threshold value for support and confidence...\")\nsuppLevels <- c(0.1,0.05,0.03,0.005)\nconfLevels <- c(0.9,0.8,0.7,0.6,0.5,0.4)\n\nruleLength <- function(confLevels,suppLevels,Data,j)\n{\n  rule=integer(length=length(confLevels))\n  for(i in 1:length(confLevels))\n  {\n    rule[i] <- length(apriori(Data, parameter = list(supp=suppLevels[j],conf=confLevels[i])))\n  }\n  return(rule)\n}\n\napriroi_optimize <- function(confLevels,suppLevels,data,name)\n{  \n    rule10 <- integer(length=length(confLevels))\n    rule5 <- integer(length=length(confLevels))\n    rule3 <- integer(length=length(confLevels))\n    rule05 <- integer(length=length(confLevels))\n\n    rule10 <- ruleLength(confLevels,suppLevels,data,1)\n    rule5 <- ruleLength(confLevels,suppLevels,data,2)\n    rule3 <- ruleLength(confLevels,suppLevels,data,3)\n    rule05 <- ruleLength(confLevels,suppLevels,data,4)\n\n    df <- data.frame(confLevels,rule10,rule5,rule3,rule05)\n    name= paste(\"Simulation of Apriroi Parameters : Field Type \",name)\n    ggplot(df,aes(x=confLevels))+geom_line(aes(y=rule10,color=\"10% Support\"))+\n        geom_point(aes(y=rule10,color=\"10% Support\"))+\n        geom_line(aes(y=rule5,color=\"5% Support\"))+\n        geom_point(aes(y=rule5,color=\"5% Support\"))+\n        geom_line(aes(y=rule3,color=\"3% Support\"))+\n        geom_point(aes(y=rule3,color=\"3% Support\"))+\n        geom_line(aes(y=rule05,color=\".5% Support\"))+\n        geom_point(aes(y=rule05,color=\".5% Support\"))+\n        labs(x=\"Confidence Levels\",y=\"Number of Rules\",title=name)+\n        theme_classic()+\n        theme(legend.title = element_blank())\n\n}\n\nrule_plot <- function(data,sup,con,name)\n{\n   rules <- apriori(data,parameter=list(minlen=5,supp=sup,conf=con),appearance = list(rhs=c(\"BodyPart=Ankle\",\"BodyPart=Knee\"),default=\"lhs\"))\n   rules.sorted <- sort(rules, by=\"lift\")\n   rules.prune <- rules.sorted[!is.redundant(rules.sorted)]\n   cat(paste(\"\\nGenerating rules for \", name, \"Turf...\\n\"))\n   cat(paste(\"Total no of rules generated \",length(rules),\" and rules considered after pruning \",length(rules.prune),\"\\n\"))\n   inspect(rules.prune)\n   #is.significant(rule,NFL.Temp.Injury.Syn)\n   #inspect(rules[is.significant(rules,NFL.Temp.Injury.Syn)])  \n   #plot(rules.prune,measure=c(\"support\",\"lift\"),shading=\"confidence\")\n   #plot(rules.prune[1:100],method=\"paracoord\", control=list(reorder=TRUE))\n   #plot(rules.prune[1:10],method=\"graph\",control=list(type=\"items\"))\n\n}\n\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% select(c(\"PlayerGamePlay\",\"PlayerDay\",\"PlayerGame\",\"Temperature\",\"BodyPart\"))\n#NFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(Weather != \"\" || Weather !=\"0\" || Weather != \"N/A(Indoors)\")\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(PlayerDay >0)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(Temperature > -999)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(PlayerGame > 0)\nNFL.Temp.Injury.Syn <- NFL.Temp.Injury.Syn %>% filter(PlayerGamePlay > 0)\n#NFL.PlayList <- NFL.PlayList %>% filter(StadiumType != \"\")\n#NFL.PlayList <- NFL.PlayList %>% filter(Position!=\"Missing Data\")\nNFL.Temp.Injury.Syn$BodyPart <- as.factor(NFL.Temp.Injury.Syn$BodyPart)\n#NFL.Temp.Injury.Syn$Weather <- as.factor(NFL.Temp.Injury.Syn$Weather)\napriroi_optimize(confLevels,suppLevels,NFL.Temp.Injury.Syn,\"Synthetic\")\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Selection of Rules for Synthetic Turf </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"Aprioi is quite popular for Market Basket Analysis. However,apriori has also been used by researchers to study passings in football game.Very simple Apriori Algorithm has been used to find rule associations. Usually support and confidence levels are required to start Apriori. As shown in the above graph, support value 0.005 and confidence value 0.8 is used to have better in depth analysis. "},{"metadata":{"trusted":true},"cell_type":"code","source":"rule_plot(NFL.Temp.Injury.Syn,0.005,0.8,\"Synthetic\")\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Conclusion </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"This report shows that **acceleration, deceleration, temperature,attribute PlayerGamePlay(i.e.Running count of the plays the player has participated in during the game),attribute PlayerDay(i.e.sequence of player’s participation), and attribute PlayerGame(i.e.the last integer of Game Id)** should be considered to predict non-contact lower limb injury. Tau value will change for change in dataset. Above variables are selected as per present dataset.Weather,Stadium Type,Position, and PlayType should also be considered to predict lower limb injury.It has been observed that Weather,Stadium Type,Position, and PlayType had high association with player's injury for earlier dataset. We need to add lhs variables manually to generate rules with Apriori. Automatic update of lhs variables with change in datset is left for furture work."},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Bibliography </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"<ul>\n<li>[1] Taylor,S. A.,Fabricant,P. D.,Khair,M. M.,Haleem,A. M.,and Drakos,M. C.(2012)\"A Review of Synthetic Playing Surfaces, the Shoe-Surface Interface, and Lower Extremity Injuries in Athletes\",The Physician and sportsmedicine,DOI: 10.3810/psm.2012.11.1989 </li>\n<li> [2] Nunes,S., and Sousa,M.\"Applying Data Mining Techniques to Football Data from European Championships\". Retrieved from https://www.researchgate.net/publication/37649621_Applying_Data_Mining_Techniques_to_Football_Data_from_European_Championships </li>\n</ul>    \n"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"background-color:steelblue\"><font size=\"3\" color=\"white\"><strong> Qualifications </strong></font></div>"},{"metadata":{},"cell_type":"markdown","source":"In 2004, I developed innovative machine at Indian Institute of Carpet Technology,Bhaodhi,India as core team member.Later on I developed/update several syllabi for Under Graduate and Post Graduate students in India. Some of the courses are well accepted by former Regional Engineering Colleges. In 2017, Springer published my Doctoral Thesis in book format and it is available on Amazon. You can have copy of my Doctoral Thesis in Top Universities throughout the world. Since 2016 I have been trying to contribute to IT industry as Operations Research Scientist.\nI did Master of Engineering in Mechanical from BITS,Pilani,India.\n\nI am grateful to Kaggle and NFL for conducting such wonderful competition.\n\nThanks,"}],"metadata":{"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}