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…

  • choose packages/functions
  • read in data
  • group_by and summarise
  • make notes using RMarkdown
  • insert pictures in an Rmd document
  • write data to csv

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

1. customise your Rmd document by adding your name as the author, a table of contents and choosing a theme that you like.

2. load the packages you will need

  • tidyverse is the general package, here is so that R knows to locate it from the data folder
library(tidyverse)
library(here)

3. read the birthweight data

make sure you label it as “frames <-” so that when you pipe it later, it knows what frames means. Also adding here::here and data in the brackets indicates what folder to read.

frames <- read_csv(here::here("data", "birthweight_data.csv"))

4. calculate the mean birthweight separately for twins and singletons

group by category, summarise my numerical value

frames %>%  
  group_by(plurality) %>% 
  summarise(mean(birthweight)) %>% 
  ungroup()
## # A tibble: 2 × 2
##   plurality `mean(birthweight)`
##   <chr>                   <dbl>
## 1 singleton               3248.
## 2 twin                    2311.

5. identify the earliest (i.e. the minimum value) gestational age for each ethicity group

frames %>% 
  group_by(child_ethn) %>% 
  summarise(min(gestation_age_w)) %>% 
  ungroup()
## # A tibble: 10 × 2
##    child_ethn                        `min(gestation_age_w)`
##    <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

6. write some notes about how group_by and summarise work with the pipe below, including a link to documentation or a blog post that you think is useful

Group by acts as a way to distinguish the qualitative variable we are looking at, while summarise looks at a quantitative measure within that group. Danielle’s video on “What is pipe?” was a good resource for this. https://i-am-learning-r.netlify.app/week1#what-is-the-pipe

7. download a picture of a baby from the internet and insert it into your document below

8. write the summary of mean birthweight by twins/singletons that you made in step 3 above to a new csv file

frames %>% 
  group_by(plurality) %>% 
  summarise(mean(birthweight)) %>% 
  ungroup() %>% 
  write_csv("bw_by_plurality.csv")

9. Knit your document and publish the output to RPubs