{"cells":[{"metadata":{"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"library(readr)\nlibrary(magrittr)\nlibrary(data.table)\nlibrary(kableExtra)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord <- read_csv(\"../input/nfl-playing-surface-analytics/InjuryRecord.csv\") %>% \ndata.table()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Lets start with some basic visualizations of our Dataset with the most important features:\n\nThe **PlayList** dataset!\n\nFirst we need to look at some basic numbers, for example how many Injuries happened on which Surface"},{"metadata":{"trusted":true},"cell_type":"code","source":"library(ggplot2)\nggplot(InjuryRecord, aes(x = Surface)) + \ngeom_bar(stat = \"count\", fill = \"grey\") +\ntheme_minimal() +\nggtitle(\"Injuries by Surface\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Here we see that in general more injuries happen in a **synthetic** surface. To answer the question, if more injuries happen on **synthetic** surface, this information is not sufficient, because the number of matches on a synthetic playfield is not taken into account yet.\n\nWhat we can check right now, is which of the injuries on the surfaces in more severe. For this we first need to transform the binary variables of the duration of the injuries into one ordered variable:"},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord[, InjuryDays := ifelse(DM_M7 != 1,\"DM_M01\",\n                                    ifelse(DM_M28 != 1, \"DM_M07\",\n                                           ifelse(DM_M42 != 1, \"DM_M28\", \"DM_M42\")))]\n\ntable(InjuryRecord[, InjuryDays])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"With this we can determine which of the injuries are more severe. So now, we can check on which surface the injuries are worse :"},{"metadata":{"trusted":true},"cell_type":"code","source":"ggplot(InjuryRecord, aes(x = Surface, fill = InjuryDays)) +\n  geom_bar(position = \"fill\") +\n  ggtitle(\"Relative Partition of the Length of an Injury\", subtitle = \"By Surface\") +\n  theme_minimal() + \nscale_fill_manual(values = c(\"lightgoldenrod1\", \"lightgoldenrod2\", \"lightgoldenrod3\", \"lightgoldenrod4\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Seems like we can fast answer the question where the most severe injuries occur and that is on the **synthetic** surface, because more injuries with at least 28 days time occur there.\n\n### Finished! Right?\n\nWell, not exactly as you will see next!\n\nNow we check the durations of the different body parts that get injured:"},{"metadata":{"trusted":true},"cell_type":"code","source":"ggplot(InjuryRecord, aes(x = BodyPart, fill = InjuryDays)) +\n  geom_bar(position = \"fill\") +\n  ggtitle(\"Relative Partition of the Length of an Injury\", subtitle = \"By Body Part hurt\") +\n  theme_minimal() +\nscale_fill_manual(values = c(\"lightgoldenrod1\", \"lightgoldenrod2\", \"lightgoldenrod3\", \"lightgoldenrod4\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Here we see that a *foot* injury is definitely more severe than the other injuries. A *knee* or an *ankle* injury is not as severe as a *foot* injury, but clearly more severe than a *toe* or a *heel* injury. (Pay attention! There is just 1 *heel* injury which is why the bar has only one color)\n\nIf we now check on which surface the body parts are injured which lead to longer injuries, then we should see that on the **synthetic** surface body parts like *foot*, *knee* and *ankle* should be injured more often than on the **natural** surface.\n\nSo, let's check:\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord[, BodyPart := factor(BodyPart, levels = t(c(\"Foot\", \"Knee\", \"Ankle\", \"Toes\", \"Heel\")), ordered = TRUE)]\n\nggplot(InjuryRecord, aes(x = Surface, fill = BodyPart)) +\n  geom_bar(position = \"fill\") +\n  ggtitle(\"Relative Partition of the Body Part hurt\", subtitle = \"By Surface\") +\n  theme_minimal() +\n  scale_fill_manual(values = c(\"red4\", \"red1\", \"orange3\", \"orange\", \"yellow\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The answer to that question is contradictory to the hypothesis above, because the percentage of body parts which lead to more injury time that were hurt is lower on the **synthetic** surface than on the **natural** surface!\n\n### Why is that?\n\nThe answer should be obvious if you think about it for a while!\n\nEven though the body parts that normally need more time to recover are relatively spoken more often injured on **natural** surface than on **synthetic** surfaces, but in fact the injuries itself are not as severe as if the same body part is hurt on the **synthetic** surface (which leads to the barplot as seen above | InjuryDays vs. Surface).\n\nSo, we should have a dependency of more severe injuries from the same bodyparts on **synthetic** surfaces than on **natural** surfaces, right?\n\nLet's check:"},{"metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"tbl1 <- table(InjuryRecord[Surface == \"Natural\", InjuryDays], InjuryRecord[Surface == \"Natural\", BodyPart])\ntbl2 <- table(InjuryRecord[Surface == \"Synthetic\", InjuryDays], InjuryRecord[Surface == \"Synthetic\", BodyPart])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Natural:"},{"metadata":{"trusted":true},"cell_type":"code","source":"tbl1","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Synthetic"},{"metadata":{"trusted":true},"cell_type":"code","source":"tbl2","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The statement made above was confirmed! Yeaaaaah!\n\nWe solved the problem!\n\nA little bit!\n\nBecause there are exceptions!\n\nSo not so much \"yeaaaaah!\", but more \"let's continue the work because or analysis is not done?\"\n\nWell, in this tables we saw that especially in the group of the *ankle* injuries there are a lot more severe injuries on the **synthetic** surface than on the **natural** surface, which was suspected before. The *knee* injuries are slightly worse on the **synthetic** surface, too, which also confirms the hypothesis from before, but the *toe* injuries are almost as severe on both surfaces and the *foot* injuries are even less severe on the **synthetic** surface than on the **natural** surface.\n\nSo just assuming that the injuries on the **synthetic** surface are more severe is wrong and does not work for all body parts."},{"metadata":{},"cell_type":"markdown","source":"So let's get to the good part:\n\n### Things to analyze in this competition:\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the different plays?\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the weather or the stadium type?\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the position of the injured player?\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the number of plays the player had before the injury?\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the direction of the movement?\n\nCan the difference between both surfaces with regard to the time of the injuries be explained by the speed?\n\n...\n\nAnd if it can not...\n\nthen...\n\nCan we just assume that injuries are more severe on the **synthetic** surface than on the **natural** one?"},{"metadata":{},"cell_type":"markdown","source":"---\n\n\n\n\nI hope you enjoyed reading this small introduction into the problem that shall be analyzed in this competition and maybe some of the questions I just stated will help you to start with your analyses and gave you some great ideas we can all discover together in this competition!\n\nI'm looking forward to your replies. I'm a team player. I would highly encourage you to openly discuss your ideas in the comments section to deepen the idea pool everyone has and create some awesome new ideas for analyzing this topic! Together we are strong!"}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":1}