Analysis code for the manuscript A population atlas of human circadian rhythms made from nationwide routine care data, by Álvaro G. León and Søren Brunak (2026).
This repository contains the R scripts that implement the results pipeline of the manuscript: population-level normalization of routine laboratory measurements, cosinor fitting of 24-hour rhythms at the population and age-stratified level, circular-linear correlation between acrophase and age, biomarker-wise logistic models of 28-day mortality, and a meta-regression of mortality effect size on circadian amplitude.
The scripts operate on a hospital laboratory database that cannot be shared for
patient-privacy reasons. To make the pipeline runnable end to end, this
repository generates two simulated datasets with the same schema as the real
tables, generated by the 00_ scripts. The demo reproduces the structure of
every result table in the manuscript. For more information, see
Data Availability in the Manuscript.
.
├── README.md
├── LICENSE
├── .gitignore
├── circadian_biomarkers.Rproj # open this in RStudio (sets the working directory)
├── 00_generate_demo_data_lab_clean.R # simulate the cleaned LAB table
├── 00_generate_demo_data_lab_mortality.R # simulate the mortality table
├── 01_data_normalization.R # outlier removal, centering, 24-h means
├── 02_cosinor_population.R # population cosinor fit
├── 03_cosinor_age.R # age-stratified cosinor fit
├── 04_acrophase_age_correlations.R # acrophase vs. age (Mardia + permutation)
├── 05_biomarker_logistic_regression.R # 28-day mortality logistic models
├── 06_mortality_metaregression.R # amplitude vs. mortality meta-regression
├── functions.R # shared helper functions
├── simulated_input_data/ # written by the 00_ scripts
└── simulated_output_data/ # written by scripts 01_ to 06_
All scripts use paths relative to the repository root, so run them with the repository root as the working directory.
| Script | Input | Output |
|---|---|---|
00_generate_demo_data_lab_clean.R |
— | demo_lab_data_clean.tsv |
00_generate_demo_data_lab_mortality.R |
— | demo_mortality_data.tsv |
01_data_normalization.R |
demo_lab_data_clean.tsv |
1.normalized_hourly_data_population.tsv, 1.normalized_hourly_data_age.tsv |
02_cosinor_population.R |
1.normalized_hourly_data_population.tsv |
2.cosinor_results_population.tsv |
03_cosinor_age.R |
1.normalized_hourly_data_age.tsv, 2.cosinor_results_population.tsv |
3.cosinor_results_age.tsv |
04_acrophase_age_correlations.R |
3.cosinor_results_age.tsv |
4.acrophase_age_correlation.tsv |
05_biomarker_logistic_regression.R |
demo_mortality_data.tsv |
5.logistic_regression_results.tsv |
06_mortality_metaregression.R |
2.cosinor_results_population.tsv, 5.logistic_regression_results.tsv |
6.summary_data_statistics_meta_regression.tsv |
Scripts must be run in numerical order. Script 05_ depends only on the
mortality table and may be run at any point after the 00_ scripts; script 03_
requires both 01_ and 02_; script 06_ requires both 02_ and 05_.
The pipeline is plain R and runs on any platform with a working R installation. Software dependencies for the demo might differ from software versions used in the analysis of the full data.
| Software | Version used | Minimum |
|---|---|---|
| R | 4.5.3 | ≥ 4.1 |
| tidyverse | 2.0.0 | ≥ 2.0.0 |
| ├─ dplyr | 1.2.0 | ≥ 1.1.0 |
| ├─ tidyr | 1.3.2 | ≥ 1.3.0 |
| ├─ readr | 2.2.0 | ≥ 2.1.0 |
| ├─ purrr | 1.2.1 | ≥ 1.0.0 |
| ├─ tibble | 3.3.1 | ≥ 3.2.0 |
| ├─ stringr | 1.6.0 | ≥ 1.5.0 |
| └─ forcats | 1.0.1 | ≥ 1.0.0 |
| broom | 1.0.12 | ≥ 1.0.0 |
| fixest | 0.14.2 | ≥ 0.11.0 |
| parallel | 4.5.3 (base R) | N/A |
| stats, methods, utils | 4.5.3 (base R) | N/A |
No other packages are required. ggplot2 and lubridate are attached as part
of tidyverse but are not used directly in this section of the pipeline.
-
Install R ≥ 4.1 from CRAN.
-
Clone the repository:
git clone https://github.com/BrunakLab/circadian_atlas.git . cd circadian_atlas
-
Install the R package dependencies:
install.packages(c("tidyverse", "broom", "fixest"))
-
Run the demo scripts in order.
The installation should take between 3-5 minutes.
The 00_ scripts generate two tab-separated tables, each 12,000 rows drawn from
1,500 synthetic patients and 4 biomarkers (cortisol, glucose, leukocytes,
creatinine), with set.seed(1):
demo_lab_data_clean.tsv(12,000 × 9) mirrors the cleaned LAB table:pid,DOB,sex,date,hour_rounded,component_simple_lookup,shown_clean,unit_clean,lab_id. Sampling hours are non-uniform, so the table reproduces the daytime-heavy draw pattern of real hospital data.demo_mortality_data.tsv(12,000 × 8) mirrors the dynamic-range table:pid,date,component_simple_lookup,shown_clean,classification(TN/TP/FN/FP),mortality_28,age,sex.
Seven files in simulated_output_data/:
| File | Rows | Cols | Contents |
|---|---|---|---|
1.normalized_hourly_data_population.tsv |
96 | 5 | normalized 24-h mean per biomarker × hour |
1.normalized_hourly_data_age.tsv |
382 | 6 | same, stratified by age group |
2.cosinor_results_population.tsv |
96 | 27 | fitted curves + cosinor parameters (MESOR, amplitude, acrophase, CIs, ZAT p, FDR q) |
3.cosinor_results_age.tsv |
384 | 26 | same, per biomarker × age group |
4.acrophase_age_correlation.tsv |
4 | 8 | Mardia R², permutation p, FDR q, acrophase velocity and direction, per biomarker |
5.logistic_regression_results.tsv |
24 | 8 | odds ratios and CIs per biomarker for classification, age and sex |
6.summary_data_statistics_meta_regression.tsv |
2 | 8 | meta-regression of log(FN odds ratio) on standardized amplitude |
Running the demo should take between 1-3 minutes depending on the computer.
This code is released under the MIT license.
A complete, detailed description of the analysis implemented here is given in the Methods section of the manuscript.