{
"cells": [
{
"cell_type": "markdown",
"id": "a28f36a6-f72d-4129-9d83-967a01084164",
"metadata": {},
"source": [
"# Analyzing More Tennis Matches, with Correlation\n",
"\n",
"**Complete by: Tuesday 27 Feb. at 9am** \n",
"Data: \n",
"\n",
"In the last workshop, we tried to figure out what makes certain tennis matches take so long. We hypothesized that perhaps certain players take longer than others, and we tested this by looking at games played by just two of tennis's big stars: Rafael Nadal and Andy Murray.\n",
"\n",
"But what if the length of matches has less to do with individual players and more to do with other factors? Today, we'll explore this question.\n",
"\n",
"## Ethical Considerations\n",
"\n",
"It's sometimes easy to imagine sports data as \"neutral,\" but just like any kind of data there are potential ethics concerns. As always we should consider the stakeholders of any data set. Who stands to gain by a data set being handled well? Who could be hurt if that same data is handled poorly? In the case of the tennis data, we should consider that professional sports are a big business, which includes the professional livelihoods of not only players but lots of support staff. Representing a sport accurately can help the people who make their livings in that sport. Likewise, sports fans are deeply committed to their favorite players and teams, and accurate data collection and management can help those fans to better interact with the sport. Misrepresenting sports data could lead to certain players or teams being underfunded, or it could even lead to rule changes that might endanger athletes' health or overall ability to perform. Good sports analysis should always take the stakeholders into account and consider the ethical implications of any analysis.\n",
"\n",
"**Begin by importing the usual libraries:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "580fb70d-2a50-401e-91b7-485eb5e51579",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "60180619-0fdd-44b8-b835-25e45d899f11",
"metadata": {},
"source": [
"In your conclusions to the last workshop, many of you pointed out that we could be more sure of our findings if we had a larger sample of data. This week we'll use a much larger data set.\n",
"\n",
"Sports analytics expert Jeff Sackmann has created [a series of tidy datasets](https://github.com/JeffSackmann/tennis_atp) on matches from the ATP Tourâ€”the official set of tournaments sponsored by the Association for Tennis Professionals. We're working with the data from the 2021 ATP Tour. **Read in the data from the URL above now:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a84551c7-5bc9-4cd6-ad04-505338ff6219",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "92752c87-388a-4cc9-9d2d-867f1a5a6de2",
"metadata": {},
"source": [
"What does each row in this dataset represent? There are many columns here (almost fifty!), and you don't need to describe each one. But in general, what kinds of information are available in the columns? (Some of the abbreviations here will be unfamiliar to you, and we'll cover that in the next step.) How is the data set different from the one we worked with last week? **Write your answers below:**"
]
},
{
"cell_type": "markdown",
"id": "6c989a03-5c6e-4a94-a481-72f4e77442e1",
"metadata": {},
"source": [
"[Your answers here.]"
]
},
{
"cell_type": "markdown",
"id": "08933cfd-1b02-4658-8a80-b5a43e57b907",
"metadata": {},
"source": [
"## Finding Correlations, Exploring the Data\n",
"\n",
"Now that we've gained some familiarity with the data, we want to see what factors might correlate with the length of tennis matches. Thankfully, the data provides us with a `minutes` variable that tells us exactly how long each match lasted. This will be our *dependent variable* for all of our subsequent analysis.\n",
"\n",
"It's up to you to choose some *independent variables* that might correlate with the length of the game. Look over the data and choose a few possible variables. You'll need to investigate the data's documentation in order to understand all the abbreviations! Thankfully Sackmann provides [a file that explains what all the column abbreviations mean](https://github.com/JeffSackmann/tennis_atp/blob/master/matches_data_dictionary.txt).\n",
"\n",
"**In this section, choose 4 independent variables from the data set, list them, and explain why you chose each one. Use your common sense and knowledge of the data to pick variables you think could plausibly have an effect on the length of the game. Remember that independent and dependent variables for correlation *must be numerical*.** \n",
"\n",
"**Then, make 4 regression plots (these are scatterplots with a regression transform) to compare each independent variable with `minutes`. Interpret each plot, explaining whether or not there appears to be a trend or correlation. (As always, make sure all plots have titles and labels, and you may need to make the regression line a different color to ensure it's visible.)**\n",
"\n",
"**Finally, calculate Pearson's correlation coefficient between each of your independent variables and `minutes`. (Keep track of these with distinct variable names.) Explain whether the coefficient says the correlation is positive or negative, strong or weak. Is this also reflected in the plots?**\n",
"\n",
"Remember that you can create new cells by clicking the `+` button above, and you can switch the cell from Code to Markdown using the dropdown. Take your time with this, and make sure you've treated all four independent variables thoroughly."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be0f6ed3-4b8f-42b6-a628-459a7eb05164",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "538c3fdb-644f-4518-b70b-e312a61c190d",
"metadata": {},
"source": [
"## Testing Correlations\n",
"\n",
"Now you've done some EDA and located some possibilities for correlation. You've tested these against your intuition about the data, but let's do some real hypothesis testing. Are we likely to find the same correlation coefficients that we found in this sample in the full population?\n",
"\n",
"**Choose *two* of the independent variables from above. Perhaps they're the ones you think are most plausible, or the ones you're most curious about. Run two separate permutation tests, testing the correlation between each independent variable and `minutes` (the length of the match).**\n",
"\n",
"**For each permutation test you will:**\n",
"\n",
"- Write out the null and alternative hypothesis.\n",
"- Run 10,000 permutations using the function we created in class.\n",
"- Graph the permutation distribution with a red line showing the observed correlation.\n",
"- Calculate a p-value.\n",
"- Interpret the plot and the p-value, explaining whether the correlation is statistically significant and/or practically significant."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c937a797-0a27-41bb-9c63-a75b91c89d7c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "8fbcdfdb-8e0b-4cea-b175-aa1df648e50b",
"metadata": {},
"source": [
"## Conclusion\n",
"\n",
"**Write a few sentences summarizing your results. Did you find any variables that seem to correlate with longer tennis matches? What did you learn about the causes of long tennis matches by doing this analysis? What limitations did you find in this data, and what are your thoughts about what to try next?**"
]
},
{
"cell_type": "markdown",
"id": "6f2f731e-7f1a-438a-8a5d-fe4214e30f0a",
"metadata": {},
"source": [
"[Your conclusion here.]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}