Hi Posit community!
I'm releasing sleepcleanr, an R package for reproducible, auditable
cleaning of sleep diary data collected via intensive longitudinal research
(ecological momentary assessment / EMA).
The problem
Sleep diary timestamps seem simple, but real-world data is messy:
- AM/PM swaps: "got up at 23:45" (typo?) vs actual 11:45 PM
- Duration entry errors: 120 minutes entered as "02:00" (HH:MM instead of MM)
- Temporal violations: "fell asleep at 11:00 PM but went to bed at midnight"
- Self-report noise: ±75 min variance in sleep onset latency across
duplicate reports
What sleepcleanr does differently
sleepcleanr flags problems for human review rather than silently
auto-fixing:
- 1,048 flagged records (out of 13,990) → human review
- 0 silent corrections
- Every change logged in reversible CSV ledgers
- Full audit trail: who changed what, when, why
Validation
Built on a 9-step validation chain:
- Synthetic benchmarks: 0.995 recall on injected errors
- Real-world redundancy: 92% agreement between duplicate diary entries
- Robustness: multiverse analysis + seed stability proof
- Methods documented: long + short forms, publication-ready figures
308 unit tests passing. All code audited for correctness.
Quick start
install.packages("sleepcleanr")
library(sleepcleanr)
# Demo on synthetic data
run_pipeline()
# Your own study: YAML config, no code changes
file.copy(system.file("config_template.yaml", package = "sleepcleanr"),
"my_study.yaml")
# Edit my_study.yaml → run_pipeline(config = "my_study.yaml")
Output
- Dataset A: Final clean data (1,048 flagged records corrected)
- Dataset B: Full audit ledger (what changed, why)
- 30+ figures: QC plots + research-ready visualizations
Why transparent cleaning matters
In behavioral science, we need to know:
- Which records are flagged and why
- What corrections were made
- Who made them
- Whether they're reversible
This builds trust with reviewers and co-authors. No black boxes.
Links
- GitHub: GitHub - cyracaid/sleepdiary-cleaner: Reproducible sleep diary data cleaning pipeline in R. Drops in your data — .rds or .csv — via a one-page config template, auto-detects and corrects timestamp errors with a documented human-in-the-loop review trail, and outputs TST/SOL/WASO/SE metrics with diagnostic figures. · GitHub
- Docs: Sleep EMA Diary Data Cleaning Pipeline • sleepcleanr
- R-universe: https://cyracaid.r-universe.dev
- CRAN: [v1.4.4, just submitted]
For researchers using EMA / intensive longitudinal methods
If you collect sleep diaries, movement logs, mood assessments, or any
timestamp-based self-report data, this architecture (detect → review → log)
is generalizable beyond sleep.
Feedback very welcome! Questions about validation, extensibility, or
methods?