Longitudinal trends in modifiable cancer risk factors in the Generations Study cohort in the United Kingdom
Analysis code for:
Jackson, I., Heath, A., Muller, D., Jones, M.E., García-Closas, M., Berrington de Gonzalez, A., Gunter, M.J. Longitudinal trends in modifiable cancer risk factors in the Generations Study cohort in the United Kingdom. Scientific Reports. 2026. https://doi.org/10.1038/s41598-026-60923-x
This repository contains the R code for a study of life course trajectories of modifiable cancer risk factors, including alcohol consumption, smoking, BMI, and physical activity (total and leisure-time). The analyses use data from the Generations Study, a prospective cohort of women in the United Kingdom.
Trajectories are modelled using linear mixed-effects models with natural cubic splines for age in the fixed effects. Mean velocity curves are used to identify periods of rapid change. Interactions between age and birth cohort are used to assess generational differences.
.
├── run_all.R # runs the full pipeline in order
├── README.md
├── renv.lock # pinned package versions
├── .Rprofile # activates renv on startup
├── renv/ # renv infrastructure (activate.R, settings.json)
├── lifestyle_trajectories.Rproj # open this to root the project (here() anchor)
├── R/ # analysis scripts (see run order below)
├── data/ # data goes here (NOT included) - see Data availability
│ └── README.md # note on the expected data file
└── results/ # generated tables and figures
├── README.md # note on generated outputs
├── tables/ # (empty - populated by the pipeline)
└── figures/ # (empty - populated by the pipeline)
Open lifestyle_trajectories.Rproj first (this roots the project so here() resolves
paths correctly), then run:
source("run_all.R")run_all.R sources the scripts in the required order. The scripts share a single
R session and rely on objects created by earlier steps, so they are not intended
to be run in isolation. The pipeline in order:
-
1.0.mlm_formatting.R- reads the data, builds the long-format modelling datasets. -
Population-level models (per exposure) - fit linear and natural cubic spline models, run model comparisons, and save fitted models to
data/mlm_models/
2.1.1.mlm_alc_linear.R2.1.2.mlm_alc_nonlinear_ncs.R2.1.3.mlm_alc_model_comparison.R2.1.4.mlm_alc_continuing.R2.2.1.mlm_bmi_linear.R2.2.2.mlm_bmi_nonlinear_ncs.R2.2.3.mlm_bmi_model_comparison.R2.3.1.mlm_totalPA_linear.R2.3.2.mlm_totalPA_nonlinear_ncs.R2.3.3.mlm_totalPA_model_comparison.R2.4.1.mlm_leisPA_linear.R2.4.2.mlm_leisPA_nonlinear_ncs.R2.4.3.mlm_leisPA_model_comparison.R2.5.1.mlm_smok_linear.R2.5.2.mlm_smok_nonlinear_ncs.R2.5.3.mlm_smok_model_comparison.R2.5.4.mlm_smok_continuing.R
-
3.0.mlm_velocity.R- differentiates the population-level spline curves to compute velocity curves -
Birth-cohort formatting and models
4.0.mlm_bc_formatting.R4.1.mlm_bc_alc.R4.2.mlm_bc_bmi.R4.3.mlm_bc_totalPA.R4.4.mlm_bc_leisPA.R4.5.mlm_bc_smok.R
5.0.project_output.R- writes tables and figures toresults/.
The data underlying this study are from the Breast Cancer Now Generations Study and are not publicly available due to participant confidentiality and consent restrictions. De-identified data may be made available to qualified researchers for approved research through the study’s controlled access process. Information on how to apply for access is available at https://thegenerationsstudy.co.uk/.
The code expects a single prepared data file at:
data/df_clean.rds
A user with approved access should place their extract at that path before running the pipeline. Variable names in the scripts reflect the data extract dated 2025-06-13 and may differ from later versions of the source data.
- R version 4.6.0 - this is also recorded in
renv.lock. - Package versions are pinned with renv.
One package, spluti (Li, Z., 2021),
used for the velocity computations, is only available from GitHub and must be
installed before restoring the renv environment:
# 1. install the GitHub-only package first
install.packages("pak")
pak::pak("ZheyuanLi/spluti")
# 2. restore the pinned package versions
renv::restore()Then open lifestyle_trajectories.Rproj and run source("run_all.R").
Running the pipeline writes tables and figures to results/ (results/tables/
and results/figures/). These outputs are not stored in the repository. They
are generated when the pipeline is run. The published versions of the tables
and figures are available in the paper.
If you use this repository in your work, please cite:
Jackson, I., Heath, A., Muller, D., Jones, M.E., García-Closas, M., Berrington de Gonzalez, A., Gunter, M.J. lifestyle-trajectories. (2026). Zenodo. https://doi.org/10.5281/zenodo.21347052
This project is licensed under the MIT License.