Back to Article
Computational Notebook
Download Source

Computational Notebook

Author

Insert Author’s Name Here

Published

September 30, 2025

Intro

This is a starter file for your “Computational Notebook” script. This script be used to run analyses using the data file(s). This script should be separate from the “Prepare Data” file that is used for update the data file(s). Every time you run the “Computational Notebook” file with the exact same data, you should get the exact same findings (i.e., reproducibility). Thus, we keep the “Prepare Data script” separate from the “Computational Notebook” file so that you update the data only when you intend to.

This document is a Quarto Notebook, which is an example of a computational notebook. Best practices for using Markdown are in the Lab Wiki here: https://devpsylab.github.io/DataAnalysis/markdown.html#bestPractices. Steps for working with computational notebooks are located in the Lab Wiki here: https://devpsylab.github.io/DataAnalysis/markdown.html#computationalNotebook

This document is a Quarto Notebook. Quarto enables you to weave together content and executable code into a finished document. When you execute code within the notebook, the results appear beneath the code. This allows you to share your analyses and results with others so that they can see the results in line with the code for reproducibility. Make sure to have only one sentence per line. For more information on the value of computational notebooks, see the article titled “The Scientific Paper Is Obsolete”. To learn more about Quarto see https://quarto.org.

Preamble

Install Libraries

In [1]:
Code
#install.packages("remotes")
#remotes::install_github("DevPsyLab/petersenlab")

Load Libraries

In [2]:
Code

library("petersenlab") #located here: https://github.com/DevPsyLab/petersenlab
library("tidyverse")
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.1     ✔ stringr   1.5.2
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code

library("sysfonts")
library("showtext")
Loading required package: showtextdb

Import Font for Figures

To use the fonts, download and install the fonts located here1: https://drive.google.com/drive/u/0/folders/1fqlrnEe7NFnWZoIrsHmr8ulDS4nhs-H3

In [3]:
Code

#Add Gotham Fonts
#sysfonts::font_add(
#  family = "Gotham",
#  regular = "Gotham-Book.otf",
#  bold = "Gotham-Bold.otf",
#  italic = "Gotham-BookItalic.otf",
#  bolditalic = "Gotham-BoldItalic.otf")
#
#showtext::showtext_auto()

Load Data

Specify Variables

Screening

Contacted to Screen

Refused Screen

Reasons People Refused the Screen

Eligible

Reasons for Ineligibility

Interested (Among Those Who were Eligible)

Reasons Eligible People Chose Not to Participate

Contacted to Enroll (Among Those Who Were Eligible and Interested)

Reasons Eligible and Interested People Were Not Contacted

Enrolled (Among Those Who Were Eligible, Interested, and Contacted)

Reasons Eligible and Interested People Were Not Enrolled

Consented (Among Those Who Were Eligible)

Reasons Enrolled People Were Not Consented

Recruitment Source

Among All of Those Screened

Among Those Who Consented

Tests of Systematic Differences Between Contacted (But Not Consented) and Consented

Describe the Sample

Sample Composition

Sex of the Participant

Race/Ethnicity of the Participant

Socioeconomic Status

Marital Status

Occupational Prestige

Educational Attainment

Duration of Procedures

Missingness

Extent of Missingness

Predictors

Outcome

Reasons for Missingness

Predictors

Outcome

Tests of Systematic Missingness

MCAR Test

Systematic Missingness of Predictors

Systematic Missingness of Outcome

Descriptive Statistics

Sample Size

Values

Frequencies

Histograms

Correlations

Bivariate Correlations

Correlation Matrices

Correlograms

Scatterplots

Scatterplot Matrix

Reliability

Internal Consistency

Inter-Rater Reliability

Cross-Time Stability Correlations

Analyses

Session Info

In [4]:
Code
sessionInfo()
R version 4.5.1 (2025-06-13)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] showtext_0.9-7    showtextdb_3.0    sysfonts_0.8.9    lubridate_1.9.4  
 [5] forcats_1.0.1     stringr_1.5.2     dplyr_1.1.4       purrr_1.1.0      
 [9] readr_2.1.5       tidyr_1.3.1       tibble_3.3.0      ggplot2_4.0.0    
[13] tidyverse_2.0.0   petersenlab_1.2.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1   psych_2.5.6        viridisLite_0.4.2  farver_2.1.2      
 [5] S7_0.2.0           fastmap_1.2.0      digest_0.6.37      rpart_4.1.24      
 [9] timechange_0.3.0   lifecycle_1.0.4    cluster_2.1.8.1    magrittr_2.0.4    
[13] compiler_4.5.1     rlang_1.1.6        Hmisc_5.2-3        tools_4.5.1       
[17] yaml_2.3.10        data.table_1.17.8  knitr_1.50         htmlwidgets_1.6.4 
[21] mnormt_2.1.1       plyr_1.8.9         RColorBrewer_1.1-3 foreign_0.8-90    
[25] withr_3.0.2        nnet_7.3-20        grid_4.5.1         stats4_4.5.1      
[29] lavaan_0.6-20      xtable_1.8-4       colorspace_2.1-2   scales_1.4.0      
[33] MASS_7.3-65        cli_3.6.5          mvtnorm_1.3-3      rmarkdown_2.30    
[37] reformulas_0.4.1   generics_0.1.4     rstudioapi_0.17.1  reshape2_1.4.4    
[41] tzdb_0.5.0         minqa_1.2.8        DBI_1.2.3          splines_4.5.1     
[45] parallel_4.5.1     base64enc_0.1-3    mitools_2.4        vctrs_0.6.5       
[49] boot_1.3-31        Matrix_1.7-3       jsonlite_2.0.0     hms_1.1.3         
[53] Formula_1.2-5      htmlTable_2.4.3    glue_1.8.0         nloptr_2.2.1      
[57] stringi_1.8.7      gtable_0.3.6       quadprog_1.5-8     lme4_1.1-37       
[61] pillar_1.11.1      htmltools_0.5.8.1  R6_2.6.1           Rdpack_2.6.4      
[65] mix_1.0-13         evaluate_1.0.5     pbivnorm_0.6.0     lattice_0.22-7    
[69] rbibutils_2.3      backports_1.5.0    Rcpp_1.1.0         gridExtra_2.3     
[73] nlme_3.1-168       checkmate_2.3.3    xfun_0.53          pkgconfig_2.0.3   

Rstudio Version

In [5]:
Code
#rstudioapi::versionInfo()

  1. You may need to ask Dr. Petersen to get access to this file.↩︎