Welcome to the PSYC3361 coding W1 self test. The test assesses your ability to use the coding skills covered in the Week 1 online coding modules.
In particular, it assesses your ability to…
It is IMPORTANT to document the code that you write so that someone who is looking at your code can understand what it is doing. Above each chunk, write a few sentences outlining which packages/functions you have chosen to use and what the function is doing to your data. Where relevant, also write a sentence that interprets the output of your code.
Your notes should also document the troubleshooting process you went through to arrive at the code that worked.
For each of the challenges below, the documentation is JUST AS IMPORTANT as the code.
Good luck!!
Jenny
#install and loading packages
install.packages("tidyverse")
library(tidyverse)
#reading BW data from csv file
birthweight_data <- read_csv(file = "data/birthweight_data.csv")
#calculating and printing mean BW by plurality
mean_BW_T_S <- birthweight_data %>%
group_by(plurality) %>%
summarise(mean_bw = mean(birthweight)) %>%
ungroup()
print(mean_BW_T_S)
## # A tibble: 2 × 2
## plurality mean_bw
## <chr> <dbl>
## 1 singleton 3248.
## 2 twin 2311.
# calculating earliest gestational age by ethnicity
min_age_eth <- birthweight_data %>%
group_by(child_ethn) %>%
summarise(min_age = min(gestation_age_w)) %>%
ungroup()
print(min_age_eth)
## # A tibble: 10 × 2
## child_ethn min_age
## <chr> <chr>
## 1 Aboriginal/Torres Strait Islander 33
## 2 African/African-American 26
## 3 Caucasian 26
## 4 East Asian 33
## 5 Hispanic/Latino 37
## 6 Middle-Eastern 28
## 7 Missing 36
## 8 Polynesian/Melanesian 28
## 9 South Asian 28
## 10 South-East Asian 29
I have no clue what this is on about…
group_by allows for the separation of data by specific variables (ethnicity, twin vs singleton, etc).
summarise allows for the calculating of statistics based off a data set.
pipes % > % allow for the combination between the two, calculating things like mean, SD, min/max for specific groups
write_csv(min_age_eth, file = "data/min_age_eth.csv")