Back to Article
Code to create Figures Box 2
Download Source

Code for use cases box 2

Author

Eduard Klapwijk

Load libraries to produce figures:

In [1]:
# load libraries
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(patchwork)
library(readr)
library(neuroUp)
Warning: package 'neuroUp' was built under R version 4.3.3

Read data from file and select complete cases:

In [2]:

# read data & select complete cases only (ignore NA)
data_luna <- read_csv("data/luna_reward-learn_dev_BOLD.csv")
New names:
Rows: 275 Columns: 8
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(1): sex dbl (7): ...1, lunaid, visitnum, age, beta, null, posrpe
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`

data_luna <- data_luna[complete.cases(data_luna), ]

Set seed and create figure with Cohens’ d for the box:

In [3]:
# set seed
set.seed(1234)

# Estimate Cohen's d
luna_cohen_fig <- estim_diff(data = data_luna,
                           vars_of_interest = c("beta", "null"),
                           sample_size = 20:232, 
                           k = 100, 
                           name = "Reward learning caudate")
# plot figure 3a
luna_cohen_fig$fig_cohens_d | luna_cohen_fig$fig_d_nozero 

Set seed and create figure with correlations for the box:

In [4]:
# set seed
set.seed(1234)

# Estimate correlations between posrpe (parametric association between BOLD and reward prediction error) and age
luna_corr_fig <- estim_corr(data = data_luna,
                           vars_of_interest = c("posrpe", "age"),
                           sample_size = 20:232, 
                           k = 100, 
                           name = "Reward learning caudate corr. with age")
# plot figure 3a
luna_corr_fig$fig_corr | luna_corr_fig$fig_corr_nozero