Before you begin, it’s important to know about merge conflicts.
Merge conflicts occur when two or more people are working on the same file at the same time.
When two collaborators make changes to the same file and push the file to their repository, git merges the two files.
If these two files have conflicting content on the same line, git will produce a merge conflict. Merge conflicts need to be resolved manually, as they require a human intervention:
To resolve the merge conflict, decide if you want to keep only your text, the text on GitHub, or incorporate changes from both texts. Delete the conflict markers <<<<<<<
, =======
, >>>>>>>
and make the changes you want in the final merge.
Ultimately, the goal is to avoid merge conflicts. One way to do this is to ensure only one person is typing in the team’s R Markdown document at any given time.
Click here to see the FAQ with step-by-step instructions for troubleshooting a merge conflict.
The link for this lab is available here: https://classroom.github.com/a/P_eZDRnq.
Please follow the same workflow/directions from lab 4 in terms of accepting the lab. Have Group Member 1 create the group and then have the other members join that group in turn. Do not make any changes to the .Rmd file until the instructions tell you do to so.
Assign each person on your team a number 1 through 4 (or 5).
The following exercises must be done in order. Only one person should type in the .Rmd file and push updates at a time. When it is not your turn to type, you should still share ideas and contribute to the team’s discussion.
Team Member 1: Change the author to your team name and include each team member’s name in the author field of the YAML in the following format. Team Name: Member 1, Member 2, Member 3, Member 4, (Group Member 5). Knit, commit, and push the changes to GitHub.
Team Members 2, 3, 4, 5: Click the Pull** button in the Git pane to get the updated document. You should see the updated name in the .Rmd file.**
We will use the tidyverse and knitr packages in this lab. You can also use the viridis for the visualizations.
library(tidyverse)
library(knitr)
Today, we will be working with data from the first three full seasons of the NC Courage, a highly successful National Women’s Soccer League (NWSL) team located near Duke in Cary, NC. The Courage moved to the Triangle from Western New York in 2017 and had three very successful first seasons, culminating in winning the championship game that was held at their stadium in Cary in 2019! (Data for this lab was sourced from the nwslR package on Github, and verified with the NC Courage website by Meredith Brown in a previous semester.)
Use the code below to load the data set.
<- read_csv("courage.csv")
courage courage
## # A tibble: 78 × 10
## game_id game_date game_number home_team away_team opponent home_pts away_pts
## <chr> <chr> <dbl> <chr> <chr> <chr> <dbl> <dbl>
## 1 washing… 4/15/2017 1 WAS NC WAS 0 1
## 2 north-c… 4/22/2017 2 NC POR POR 1 0
## 3 north-c… 4/29/2017 3 NC ORL ORL 3 1
## 4 boston-… 5/7/2017 4 BOS NC BOS 0 1
## 5 orlando… 5/14/2017 5 ORL NC ORL 3 1
## 6 north-c… 5/21/2017 6 NC CHI CHI 1 3
## 7 north-c… 5/24/2017 7 NC NJ NJ 2 0
## 8 chicago… 5/27/2017 8 CHI NC CHI 3 2
## 9 north-c… 6/3/2017 9 NC KC KC 2 0
## 10 north-c… 6/17/2017 10 NC BOS BOS 3 1
## # … with 68 more rows, and 2 more variables: result <chr>, season <dbl>
For each exercise, show all relevant code and output used to obtain your response. Write all narrative in complete sentences, and use clear axis labels and titles on visualizations.
Team Member 1: If you haven’t already, change the author to your team name and include each team member’s name in the author
field of the YAML in the following format. Team Name: Team member 1, Team member 2, Team member 3, Team member 4
.
Team member 1: Type the team’s response to Exercises 1 and 2.
How many observations are in this dataset? What does each observation represent? (You do not need to create a code chunk here)
Each season the Courage play 26 games. We want to find out whether they win more in the early, middle or late season.
seasonal_category
that classifies NC courage games as early
(games 1-9), middle
(games 10-17), or late
(18-26) season.win
that takes the value 0
if the courage lose and 1
if they win.seasonal_courage
and print it to the screen.Team member 1: Knit, commit and push your changes to GitHub with an informative commit message. Make sure to commit and push all changed files so that your Git pane is empty afterwards.
All other team members: Pull to get the updated documents from GitHub. Click on the .Rmd file, and you should see the responses to exercises 1-3.
Team Member 2: It’s your turn! Type the team’s response to exercises 3 - 4. :::
seasonal_category
to be in logical order. To achieve this, we will use the factor()
function to make both of these variables factors (categorical variables with ordering) and specify the levels we wish to use.The code to reorder levels for seasonal_category
is below.
seasonal_courage
.early
then middle
, then late
). Hint: what dplyr
verb changes the order of output?# seasonal_courage %>%
# mutate(seasonal_category =
# factor(seasonal_category,
# levels = c("early", "middle", "late"),
# ordered = TRUE))
Team member 2: Knit, commit and push your changes to GitHub with an informative commit message. Make sure to commit and push all changed files so that your Git pane is empty afterwards.
All other team members: Pull to get the updated documents from GitHub. Click on the .Rmd file, and you should see the responses to exercises 3 - 4.
Team Member 3: It’s your turn! Type the team’s response to exercise 5. :::
home_courage
that takes values “home” if Courage is the home team and “away” if Courage is the away team, save this data frame.Using the data frame above, create a 3 x 3
contingency table (dimensions are including column/row names) with - columns denoting whether or not a game is home
or away
for the Courage and - rows denoting whether the Courage win, lose or tie.
Bayes’ theorem tells us that
\[ P(\text{tie} \ | \ \text{home}) = \frac{P(\text{home} \ | \ \text{tie}) P(\text{tie})}{P(\text{home})} \]
Using Bayes’ theorem, find and report the conditional probability a game is a tie given a game is home. Check your result using the contingency table.
Finally, is the probability of a tie independent of the Courage playing at home or away? Why?
Team member 3: Knit, commit and push your changes to GitHub with an informative commit message. Make sure to commit and push all changed files so that your Git pane is empty afterwards.
All other team members: Pull to get the updated documents from GitHub. Click on the .Rmd file, and you should see the responses to exercises 3 - 4.
Team Member 4: It’s your turn! Type the team’s response to exercises 6 and 7. :::
total_pts
that denotes the total number of points scored in each game.courage_pts
that shows the number of points Courage scores in each game (hint: sometimes Courage is the away team, sometimes they are the home team).opponent_pts
that show the number of points the opposing team scores per game.Plot - Create a scatter plot of opponent_pts
(y) vs courage_pts
(x). - Color the scatter plot by whether the Courage are home
or away
. - Add geom_jitter
as well as the line \(y = x\) using the code below. - Facet your plot by season
- Be sure to include informative titles for the plot, axes and legend. What do you notice?
# ggplot(...code here...) +
# geom_jitter(width = 0.1, height = 0.1) +
# geom_abline(slope=1, intercept=0)
Team member 4: Knit, commit and push your changes to GitHub with an informative commit message. Make sure to commit and push all changed files so that your Git pane is empty afterwards.
All other team members: Pull to get the updated documents from GitHub. Click on the .Rmd file, and you should see the team’s completed lab! :::
Go back through your write up to make sure you followed the coding style guidelines we discussed in class (e.g. no long lines of code).
There should only be one submission per team on Gradescope.
Component | Points |
---|---|
Ex 1 | 2 |
Ex 2 | 8 |
Ex 3 | 3 |
Ex 4 | 8 |
Ex 5 | 12 |
Ex 6 | 11 |
Workflow & formatting | 6 |