Skip to content

Repository files navigation

Psychology Analysis Template

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.

Structure

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

Worked example (simulated data)

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.qmd

How the pipeline works

  1. 01_data_cleaning.qmd is the only file that reads data/raw/. It documents every transformation and writes data/processed/analysis_data.rds.
  2. 0207 each load that one processed file — so cleaning decisions live in a single place and downstream reports never diverge.
  3. Tables/figures are saved to output/ via the save_table() / save_fig() helpers and shown inline.

Getting started

# 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.

Standalone files & sharing

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.

Adapting to your study

  • Replace data/raw/survey.csv with your export (any format rio reads: .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 and group — rename to match your scales. Delete any stage you don't need.

Reproducibility notes

  • A fixed set.seed() in setup.R makes bootstraps/simulations reproducible.
  • freeze: auto re-runs a document only when its source changes.
  • Consider renv::init() to lock exact package versions per project.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages