> []# PSYC3361: Presentation Transcript
*(Alesha)*
**Intro**
Hi guys, let’s get into the presentation!
Firstly, we want to discuss the article background with you!
**Slide 1**
It is known that emotional wellbeing improves across the age lifespan, yet it is unclear how this brings age-related advantages in humans.
To answer this question, the experimenters examined age groups and their emotional experience with the COVID-19 pandemic to determine — would emotional gains persist in older individuals when exposed to prolonged and inescapable stress compared to younger individuals?
So, the study preregistered a sample of 970 Americans between 18-76 years, with a final sample of 945. The participants self-reported a range of measures, as you can see here.
The study results extend on previous research, demonstrating that older adults have greater emotional wellbeing and resilience persisting in the face of prolonged and inescapable stress by prioritising on positive, meaningful life events.
Moving on to our reproducibility goals
**Slide 2**
We set out to reproduce their demographic and descriptive stats for the reported variables. Our demographics reproduced, but sadly none of our descriptive stats reproduced but these differences were insignificant with decimals being off. There were also some descriptive stats missing such as some individual items and personality traits.
We then reproduced Table 1 which consisted of 29 emotions with their corresponding means, standard deviations, and 95% confidence intervals which all seemed to reproduce nicely.
Lastly, we set out to reproduce Figure 1 which consisted of four scatterplots examining positive and negative emotions against frequency and intensity of emotional experience. It seemed that these plots reproduced, however, we cannot confirm this, as correlation coefficients were not given. Yet, we see a general trend of older participants having lower frequency and intensities for negative emotions and higher for positive emotions.
And now ill pass onto Daniel to talk about our challenges!
*(Daniel)*
**Slide 3**
So our first challenge was simply getting the rename function to work for most of us. Yeah, basic, but it WAS a problem! We looked at using quotation marks, different commas, colons but those did nothing. We even shared the code that worked on ONE computer but it still did not rename the variables for the rest of us. Then, Google came in handy. By copying and pasting the exact error message we wound up on discussion boards where other people experienced the same problem. Here we found that inserting ‘dplyr::’ before the rename() function, would tell R that we want to use the rename() within the dplyr package. And it finally worked! Interestingly, this seemed to be a Mac, rather than windows problem... shows that different technologies may require different solutions! And it showed us how to SEARCH on Google a bit better for troubleshoots.
**Slide 4:**
A later challenge was creating the means and SD table efficiently… We figured that we could code each mean and SD by itself, rounded to three decimal places as shown here, then plop it into a table. This is not wrong, but we had 29 emotions to code. A little bit tedious I’d say.
OVERCOMING IT: We first thought that this would be the only way to do it, which was not inherently wrong again; but Kritika found a more efficient way by creating a new dataset and then applied code that was able to produce means and sd to the whole dataframe! So much more efficient, just needed a fresh eye… BUT that leads us to our other challenge - figuring out how to produce the CIs in the table. For about 2 weeks, it seemed like nothing worked.So, back to doing everything MANUALLY? 29 times? Thankfully, no, because again we needed a fresh eye and a little push from Yuki to find a more efficient way by creating a new data frame and use the mutate function to apply the CI formula across all 29 emotions. And that’s why coding like caterpillars is the way.
*(Kritika)*
**Slide 5:**
So what were our triumphs?
Producing figure 1 was probably the biggest one we had! We had to create a 4 plot figure from scratch using only our coding skills and the data we were given. For me (and I think my group can agree), it seemed like an incredible feat. So if we look at the figure, you can see we had to reproduce 4 different scatter plots and each had different features to it. For example, the top right one had no ticks, labels or information, just a title. And this can be contrasted with the bottom left one. What this means is that each scatterplot required different coding so it was not an easy copy and paste job. I started with the ‘Positive Emotions’ because as a novice it seemed the most easiest to reproduce, and enabled me to create a base code for the other plots. And the code for this plot is on the right! [show code]. Once we had the four individual scatter plots when then had to merge them together so it would become one figure, which required even more code.
```
scatterplot2 <- ggplot(data = csv_data) +
geom_point(alpha = 0.05,
size = 2.5,
mapping = aes(
x = age,
y = positive_frequency)) +
geom_smooth(
mapping = aes(
x = age,
y = positive_frequency
),
method = lm,
lwd = 1.5,
colour = "black",
fill = "darkgray",
se=TRUE) +
ylim(0, 2.5) +
theme_minimal() +
theme_apa() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
theme(plot.margin = margin(0.1, 0.9, 0.1, 0.3, "cm")) +
ggtitle(label = "Positive Emotions") +
theme(plot.title = element_text(vjust = 0.5)) +
theme(plot.title = element_text(face = "plain")) +
theme(plot.title = element_text(hjust = 0.5))
```
**Slide 6:**
So another one of our triumphs would be to do with reproducing Table One.
While figuring out the code for the confidence intervals in and of itself was a massive triumph, figuring out how to format the table, so that when we knitted it into a PDF, it would be in APA formatting was quite challenging. But thanks to Alesha we were able to figure it out! As per APA we need to have the lower and upper CI within the one cell and then separated by a comma and encased within square brackets. This required us to have concatenated data - which means to have a sequence of data within the one cell. So, here we had to paste the lower and upper CI’s and then insert a comma and space between them. The first code was used for this: [show code].
```{r}
positive_frequency_concatenated_ci <- data.frame(
paste(positive_frequency_total_ci$positive_frequency_lci,
positive_frequency_total_ci$positive_frequency_uci,
sep = ", ")) %>%
dplyr::rename("95% CI" =
paste.positive_frequency_total_ci.positive_frequency_lci..positive_frequency_total_ci.positive_frequency_uci..)
```
Then we needed to add the square brackets using the second lot of code: [show code]
```{r}
# add square brackets around CI
positive_frequency_concatenated_ci$"95% CI" <- with(positive_frequency_concatenated_ci,
paste0("[", positive_frequency_concatenated_ci$"95% CI", "]"))
```
So here we are telling R to paste a square bracket before and after the confidence intervals. The above code produce the following output and we applied it to the whole dataframe to produce table 1.
---
(Charlie)
Slide 7:
Across our varied experiences in the term in experimenting with novel code, our group learnt the following key points about learning R.
Firstly, openness to mistakes. Learning R requires an acceptance of the process of trial-and-error. As a team, we became used to consistent error messages, and learnt to embrace our mistakes as stepping stones rather than barriers. This was most applicable to us when refining the data set in preparation for Figure 1. You can see here (point) that I made the basic mistake of encoding my renamed variables within a name that was the same as the original dataset. This created issues with reproducing the scatterplots required for Figure 1.
This brings us to the second point, the importance of asking questions and seeking diverse sources. As previously discussed by Daniel and Kritika, many of our group members experienced diverse initial issues with the renaming function. Although we discussed this as a group, we quickly realized that we had to seek external sources, and decided to seek Yuki in our Week 5 Lab. Her solution is shown here (point) - she explained that we had to rename the piped dataset differently to the original to ensure that the integrity of the original data. This reinforced the importance of seeking a diverse range of support when faced with roadblocks, including Google search.
---
Slide 8:
And finally, we learnt that learning R requires flexible solutions. Although we may want to have the cleanest and most refined code, learning R requires us to stop being such perfectionists sometimes! This is best highlighted by some of our creative and laughably simple solutions. For example, when we first develop Table 1, we did not indent the emotions under their ‘Positive’ and ‘Negative’ subheadings. Initially, we found that we could just insert 2 spaces before each variable, however later Alesha found indent functions within the gt package, after first exploring the Flextable and kableExtra packages, that provided a more sophisticated and formal solution. Regardless, openness and appreciation of the flexibility of R is key to learning – sometimes, the ‘clean code’ can also be the most complicated to find.
---
(Angie)
Slide 9:
So, what did we learn about computational reproducibility?
Through our coding experience, we learn that…
• Reproducibility is difficult even with open data.
Even if the data was open, it does not mean it is easily reproducible. However, in our paper, the data was not completely open either. The individual items of subjective health were missing, and data from excluded participants were also missing. This meant that we could not reproduce exactly to what was in the article.
Further we learnt that...
It takes a lot of time and effort to reproduce code.
Our study contained 107 variables which was A LOT! So, this meant there would be a lot of coding for the separate variables. However, we always attempted to find easier solutions and we attempted to continually simplify the formatting for figures and scatterplots.
Slide 10:
So, what about working in a team?
As advised by Kate, we decided to not do the approach of divide and conquer and instead allowed everyone to try out the coding for themselves. We wanted to do this so everyone could have a taste of coding and because it allows us to bounce ideas off each other while working on it. This wouldn’t have occurred if each person was allocated to do one part. This allows for diversity as everyone has different strengths and team members were able to do tasks at their own pace and at their own ability.
This meant that…
Communication is essential, delivered through weekly meetings. Sharing our code on a shared Hackmd allowed us to communicate our progress and allows us to work cohesively together where we would troubleshoot whenever someone came across an issue. With our approach, it also meant that sometimes we get different ways of reproducing the same figures and tables and sometimes our methods overlapped, therefore, we had to communicate and choose which method would be best and most efficient to use or mesh the ideas together.
---