A modular, reproducible Quarto template for psychology data analysis. Each stage is its own document, shares one setup file, and produces APA-style-ish tables and figures you can drop into a manuscript.
Analysis_Template/
├── _quarto.yml # project + shared HTML/output settings
├── R/
│ ├── setup.R # packages, options, paths, APA helper functions
│ └── make_example_data.R # synthetic data so the template runs out-of-the-box
├── 01_data_cleaning.qmd # raw → analysis-ready (data/processed/analysis_data.rds)
├── 02_descriptives.qmd # skimr overview + gtsummary "Table 1" + distributions
├── 03_reliability_correlations.qmd # Cronbach's α / ω + correlation matrix
├── 04_regression_glm.qmd # lm & logistic, assumption checks, APA tables
├── 05_anova_ttests.qmd # t-tests & (RM-)ANOVA, effect sizes, post-hoc
├── 06_cfa_sem.qmd # lavaan CFA + SEM/mediation with path diagrams
├── 07_network_analysis.qmd # bootnet/qgraph psychometric network
├── data/{raw,processed}/ # raw is read-only; processed is generated
└── output/{figures,tables,_site}/ # saved artefacts + rendered site
The example/ folder is a self-contained demo: it simulates data from a
known mediation model and runs the full pipeline on it, so you can see every
analysis in action and check that the SEM recovers the true effects. See
example/README.md. It saves data with .RData (bundling the dataset with its
ground-truth parameters); the main pipeline uses .rds for its single dataset.
source("example/R/simulate_data.R")
# quarto render example/example_analysis.qmd01_data_cleaning.qmdis the only file that readsdata/raw/. It documents every transformation and writesdata/processed/analysis_data.rds.02–07each load that one processed file — so cleaning decisions live in a single place and downstream reports never diverge.- Tables/figures are saved to
output/via thesave_table()/save_fig()helpers and shown inline.
# 1. Generate the example dataset (or drop your own file in data/raw/):
source("R/make_example_data.R")
# 2a. Render EVERYTHING, in order, into output/_site/:
# (terminal) quarto render
# 2b. Or render a SINGLE file standalone (each .qmd carries its own full YAML):
# (terminal) quarto render 04_regression_glm.qmd
# (RStudio) open the .qmd and click "Render"setup.R uses pacman to install any missing packages automatically the first
time you render.
Every .qmd has its own complete format: header, so any file renders on its
own without depending on _quarto.yml. Output uses embed-resources: true, so
each report is a single self-contained .html (images/CSS/JS embedded as
base64 — no sidecar _files/ folder). Just email or upload the one HTML file.
_quarto.yml is kept minimal on purpose: it only anchors the project root (so
here::here() resolves) and lets quarto render build the whole set at once.
- Replace
data/raw/survey.csvwith your export (any formatrioreads:.csv,.xlsx,.sav, ...). - Edit the variable names in
01_data_cleaning.qmd(item prefixes, factors, reverse-scored items, exclusion rules). - The analysis files reference
bdi_*/cfs_*items andgroup— rename to match your scales. Delete any stage you don't need.
- A fixed
set.seed()insetup.Rmakes bootstraps/simulations reproducible. freeze: autore-runs a document only when its source changes.- Consider
renv::init()to lock exact package versions per project.