The mean depression score was `r mean(data$depression)`
(SD = `r sd(data$depression)`).PSY 410: Data Science for Psychology
2026-05-27
We opened this course with a striking finding: only 36% of psychology studies replicated.
Part of the problem was that analyses couldn’t be reproduced — even by the original authors. Data was cleaned by hand. Numbers were copied into Word documents. Code only ran on one laptop.
Quarto is part of the solution. Today we learn to write documents where the analysis is the report.
One document contains:
Benefits:
Quarto is a publishing system that combines:
It’s the evolution of R Markdown (same company, newer technology).
At the top of every .qmd file:
This controls:
Markdown is a simple way to format text:
Surround R code with three backticks:
When you render, both the code and output appear in the document.
In RStudio:
Render = convert your .qmd to the final output (HTML/PDF/Word)
Click the Render button (or Ctrl/Cmd + Shift + K)
Quarto will:
Add options with #| at the top of a chunk:
| Option | What it does | When to use |
|---|---|---|
echo: false |
Hide the code, show results | Final reports |
eval: false |
Show code, don’t run it | Example code |
include: false |
Run code, hide everything | Loading packages |
message: false |
Hide messages | Loading tidyverse |
warning: false |
Hide warnings | Final reports |
```{r}
#| fig-width: 8
#| fig-height: 6
#| fig-cap: "Depression scores by condition"
ggplot(data, aes(x = condition, y = depression)) +
geom_boxplot()
```fig-width / fig-height — size in inchesfig-cap — adds a caption below the figureEvery document should start with a setup chunk:
include: false means the chunk runs but nothing shows in the outputNever hard-code numbers!
❌ Bad:
In your text, you write r expression and Quarto fills in the result.
Use round() to control decimal places:
Create a new Quarto document (File → New File → Quarto Document):
tidyverse and a dataset (try mpg)Time: 10 minutes
Pros:
Cons:
Pros:
Cons:
Pros:
Cons:
You can render to multiple formats:
Then choose which to render in RStudio dropdown.
| Condition | N | Mean | SD |
|---|---|---|---|
| Control | 30 | 18.2 | 5.1 |
| CBT | 30 | 12.4 | 4.8 |
| Mindfulness | 30 | 14.1 | 5.3 |
For publication-ready tables:
gt is powerful but beyond our scope — use kable() for now.
#| label: load-data)here::here("data/file.csv")#| cache: trueproject/
├── my-analysis.qmd
├── data/
│ └── survey_data.csv
├── scripts/
│ └── helper_functions.R
└── output/
├── my-analysis.html
└── figures/
Keep your .qmd file in the root, data in data/, outputs separate.
Convert your final project draft to a Quarto document (.qmd):
kable()This will become your final project report!
For you:
For science:
Quarto can create:
You’re learning a tool you’ll use for years.
echo, eval, include) control what appearsknitr::kable() for simple, gt for fancy📖 Read:
✅ Do:
Quarto means your analysis and your report are the same document. Change one, the other updates. That’s reproducibility.
See you Monday for practice & review!
PSY 410 | Session 16