What were the goals for this week

The goal for this week was to get the VR done. Now, up until this week I hadn’t started on the exploratory Qs yet so I had a lot to work on

How did I go about achieving these goals?

To be honest this learning log would be a bit too long if I went through every little bit of code that I wrote and everything I learnt this week, so I’m just going to pick a few highlights. The first was learning how to write my own functions. Now, this is something that I’ve done a lot in other programming languages but up until this point I’d never really needed to do it. In the context of keeping my code nice and neat however, I decided to spend some time figuring it out in R.

Functions

library(tidyverse)
library(gt)
library(palmerpenguins)
library(sm)

dat <- penguins

The first thing to do is to write my function and decide what the inputs will be. For this example let’s make a function that plots out a scatterplot, based on the x and y axis supplied to the function.

plot_func <- function(data, x, y){
  output <- ggplot(data = data, aes(x = x, y = y)) +
    geom_point()
  return(output)
}

Now let’s see the function in action!

plot_func(dat, dat$bill_length_mm, dat$bill_depth_mm)

You can see how if we were to be plotting out multiple scatterplots, this would save a lot of time and make our code a lot more readable!

GT

The next thing I learnt was how to use the gt function. As we did a divide and conquer approach, I had very minimal exposure to GT throughout the term so tackling some exploratory Qs that required the use of tables was a bit difficult at first. However, it turned out to be an extremely intuitive package to use. We first use the gt() function to set everything up.

dat <- dat %>% 
  filter(island == "Biscoe", species == "Adelie", sex == "female")

gt_tbl <- gt(dat)

gt_tbl
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex year
Adelie Biscoe 37.8 18.3 174 3400 female 2007
Adelie Biscoe 35.9 19.2 189 3800 female 2007
Adelie Biscoe 35.3 18.9 187 3800 female 2007
Adelie Biscoe 40.5 17.9 187 3200 female 2007
Adelie Biscoe 37.9 18.6 172 3150 female 2007
Adelie Biscoe 39.6 17.7 186 3500 female 2008
Adelie Biscoe 35.0 17.9 190 3450 female 2008
Adelie Biscoe 34.5 18.1 187 2900 female 2008
Adelie Biscoe 39.0 17.5 186 3550 female 2008
Adelie Biscoe 36.5 16.6 181 2850 female 2008
Adelie Biscoe 35.7 16.9 185 3150 female 2008
Adelie Biscoe 37.6 17.0 185 3600 female 2008
Adelie Biscoe 36.4 17.1 184 2850 female 2008
Adelie Biscoe 35.5 16.2 195 3350 female 2008
Adelie Biscoe 35.0 17.9 192 3725 female 2009
Adelie Biscoe 37.7 16.0 183 3075 female 2009
Adelie Biscoe 37.9 18.6 193 2925 female 2009
Adelie Biscoe 38.6 17.2 199 3750 female 2009
Adelie Biscoe 38.1 17.0 181 3175 female 2009
Adelie Biscoe 38.1 16.5 198 3825 female 2009
Adelie Biscoe 39.7 17.7 193 3200 female 2009
Adelie Biscoe 39.6 20.7 191 3900 female 2009

Then, we can use some handy functions to make our table prettier, such as cols_hide() which hides columns we don’t want.

gt_tbl <- gt_tbl %>% 
  cols_hide(columns = bill_length_mm:body_mass_g)

gt_tbl
species island sex year
Adelie Biscoe female 2007
Adelie Biscoe female 2007
Adelie Biscoe female 2007
Adelie Biscoe female 2007
Adelie Biscoe female 2007
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2008
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009
Adelie Biscoe female 2009

Density plots

Another thing I learnt was density plots! With the sm package, I can make density plots, as well as compare density plots with each other.

dat2 <- penguins %>% 
  drop_na()

sm.density.compare(dat2$bill_length_mm, dat2$species, xlab = "Bill length")
title(main = 'Bill length of different species')

colfill <- c(2:(2+length(levels(dat2$species)))) #makes elements for the legend

legend("topright", levels(dat2$species), fill = colfill)

REAL learning log

I just saw the slack post and I was already halfway through my learning log and didn’t feel like throwing it away so I’m just going to continue it here.

What makes a good team

I was definitely blessed with probably my favourite group I’ve ever worked in during uni. Everyone was extremely friendly, hardworking, accommodating, and genuine throughout the entire term. We already have plans to sit in each others’ classes, and now that we’re at the point where we’ve probably been learning from home just as long as we’ve had a ‘conventional’ university experience, it’s all the more unexpected (in a good way) that I was able to bond with my group members as much as we have. I think what definitely brought us closer together than just group mates was the initial activity where we aired out things we don’t like about working in groups. Getting to see everyone in a more casual and lighthearted sense where we were just ragging on about previous groups we hated working in definitely set the tone for our group to be more casual and laid back (in terms of how we acted towards one another). This is definitely something to keep in mind for future group work I find myself in!

The open science movement

When I heard about the open science movement gaining traction in recent years, I thought that science was on a bright road ahead into the future. Now that I’ve had some hands on experience with reproducibility, I can see that there is so so much more to be done to address the issues that have plagued empirical research in general. This isn’t to say that everything is on the authors though - the culture that has been established with how journals publish papers has a lot to do with why papers often fabricate results, or intentionally make their analyses difficult to replicate. Furthermore, journals don’t do enough to guide their authors on how to make their data reproducible, nor do they adequately hold their authors to the standards required in order for their data to be reproducible. There needs to be a consistent framework across all scientific papers, so that the exact same process can be used every time to find out how exactly the author came to their results and conclusions in the paper. Coding needs to be a bigger part of many undergraduate courses in order to get everyone familiar with how to code as this is essential to making materials open and accessible to all.

The next steps in my education

What this course has really opened my eyes to is the value of programming and statistics in psychology. I’ve always been ok with basic programming concepts as I have experience with C and Python, as well as HTML/CSS, but because R is used for a very different purpose than what I was using other languages for, I really have to work with R a lot more to become more familiar with the language, the functions, and making my code more efficient and understandable. I also need to spend a lot of time studying statistics, as I often found myself very lost in the exploratory questions whether I should use certain statistical tests or not. The ones that I did use, I am still not entirely sure if they were used appropriately. As someone who plans to do honours next year, it’s crucial that I really nail these concepts down for my project next year.

Final thoughts

I would just like to say a massive thank you to everyone has made this course possible, as well as all my peers I have worked or interacted with throughout the term. This term has been really really crazy for me in all aspects of my life and I’m super glad I was able to do probably the most enjoyable course of my 3 years in university so far in this term specifically. I’m not sure how this course usually runs in a non-COVID era, but I can say for sure that I think the course that I did should be in the repertoire of every psychology student, even if they aren’t planning on doing honours. The passion that goes into this course and its curriculum stands out from every angle and that’s a difficult praise to make for most courses.