8 Your Assignment

This assignment is designed to help you rapidly generate summary numbers and create graphs from data you will find as a sports scientist or coach. There are two things to note:

  1. With the graphs created, export it and paste into your word assignment document.

  2. I will signpost to you in the assignment document which section of code I require you to paste into the assignment.

The assignment is EASY!!! I am only asking you to copy and paste relevant recipes which you have learned, and edit relevant values in the function’s arguments. For example, when you see the value XXX, I am asking you to replace it with the relevant value. I am NOT going to ask you to create codes from scratch. I am not cruel.

To do your assignment, follow these steps:

  1. In your desktop’sse201 folder, created in learning check 4.2.

  2. Create a project called assignment inside the folder. See Recipe 4.2.

  3. Download the R script in this link assignment_analysis.R. Save this script into the se201/assignment folder. When you open it, you should see the codes below.

  1. Inside se201/assignment folder, create a data folder. Put all your raw Excel data into the data folder. All raw Excel data for this assignment will be on SE201 Moodle>Assessment Information.

8.1 Tasks to complete

1: Import data. Replace XXX with your Excel file’s name. See Recipe 5.2.

2: Make the group FMS data, dat_fms, wide to long with three columns: id, task and score. The task column contains the names of the FMS tasks, and the score column contains the values of the FMS tasks. See Recipe 6.3.

3: For each athlete and per FMS task, keep the score with the lower values. After, for each FMS task and each score category of 0, 1, 2, or 3, count, the number of athletes within it. See Recipe 6.8.

4: Create a group FMS barplot, where the variable task is on the x axis, the count is on the y axis, and FMS score as the fill color. See Recipe 7.3.

5: For each athlete and per FMS task, keep the score with the lower values. Thereafter, for each athlete, sum the score over the seven FMS tasks. Find the group mean and standard deviation FMS score.See Recipe 6.8.

6: Select the row that belongs to athlete_a. See Recipe 6.7.

7: Make the individual athlete a FMS data wide to long with three columns: id, task and score. The task column contains the names of the FMS tasks, and the score column contains the values of the FMS tasks. See Recipe 6.3.

8: Create an FMS barplot for athlete a. Plot a bar graph of task as the x axis, and score as the y axis, fill colour set to the different tested side. See Recipe 7.3. Save the plot - See Recipe 7.8.

9: Drop jump symmetry. Calculate the maximal vertical acceleration of the good and bad leg. Use the vertical acceleration signal highg_az_m/s/s. Then use it to calculate the symmetry index during a single-leg drop land. Replace XXX with the appropriate value. See Recipe 6.5.

8.2 Codes

This is the codes you will see in the script downloaded.



## -----------------------------------------------------------------------------

## load up the packages we will need

if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, # All purpose wrangling for dataframes
               openxlsx) # writing excel documents

## Import data (Task 1)

# Import excel data

## This is the FMS results of the team

dat_fms <-  read.xlsx (xlsxFile = "XXX",
                       sheet = "XXX")

## Accelerometry findings of the bad leg from a drop land task

bad_leg_accl <-  read.xlsx (xlsxFile = "XXX",
                       sheet = "XXX")

## Accelerometry findings of the good leg from a drop land task

good_leg_accl<-  read.xlsx (xlsxFile = "XXX",
                       sheet = "XXX")

## Make the group FMS wide to long (Task 2) ------------------------------------

# Make data wide to long

dat_long <- dat_fms %>% # original data
  pivot_longer(cols = -id,
               names_to = "XXX",
               values_to = "XXX")

# Split task column

dat_long <- dat_long %>%
  mutate (
    side = case_when(
      str_detect(task, "R_") ~ "right",
      str_detect(task, "L_") ~ "left",
      TRUE ~ "central"
    )) %>%
  mutate (task = str_remove_all(task, "R_|L_"))

## Count number of athletes per task subscore (Task 3) -------------------------

# Count

fms_count <- dat_long %>%
  group_by(XXX, XXX) %>%
  summarise (score = XXX (score)) %>%
  group_by (task, score) %>%
  summarise (count = XXX())

## Plot the group FMS count data (Task 4) --------------------------------------

# Make factor

fms_count <- fms_count %>%
  mutate (score = factor (score, levels = c("0", "1", "2", "3")))

############# ********** Code 1 (start)********** ##############################

## Group barplot

ggplot(fms_count) + 
  geom_col(aes(x = XXX, y = XXX, fill = XXX), position = "dodge")+ 
  scale_fill_discrete(drop=FALSE)

############# ********** Code 1 (end)********** ################################

## Summary statistics of the total FMS score for the team (Task 5) -------------

############# ********** Code 2 (start)********** ##############################

# Total

fms_total <- dat_long %>%
  group_by(id, task) %>%
  summarise (score = XXX (score)) %>%
  group_by (id) %>%
  summarise (Total = XXX (score))

# summary

fms_summary <- fms_total %>%
  summarise (Mean = XXX (Total),
             Sd = XXX (Total))

############# ********** Code 2 (end)********** ################################

## Filter out athlete a data (Task 6) ------------------------------------------

athlete <- dat_fms %>%
  filter (XXX == "XXX")

## Make the athlete FMS wide to long (Task 7) ----------------------------------

athlete_long <- athlete %>% # original data
  pivot_longer(cols = -id,
               names_to = "XXX",
               values_to = "XXX")

# Split task column

athlete_long <- athlete_long %>%
  mutate (
    side = case_when(
      str_detect(task, "R_") ~ "right",
      str_detect(task, "L_") ~ "left",
      TRUE ~ "central"
    )) %>%
  mutate (task = str_remove_all(task, "R_|L_"))

## Plot the individual athlete's FMS data (Task 8) -----------------------------

############# ********** Code 3 (start)********** ##############################

ggplot(athlete_long) + 
  geom_col(aes(x = XXX, y = XXX, fill = XXX), position = "dodge")

############# ********** Code 3(end)********** ################################

## Analyze drop jump data (Task 9) ---------------------------------------------

############# ********** Code 4 (start)********** ##############################

# Maximal bad leg impact value
max_bad_ampl <- max(bad_leg_accl %>% select (XXX))

# Maximal good leg impact value
max_good_ampl <- max(good_leg_accl %>% select (XXX))

# Symmetry index 

symmmetry_index <- 
  ((2* (max_bad_ampl - max_good_ampl))/(max_bad_ampl + max_good_ampl)) * 100


############# ********** Code 4 (end)********** ################################