Scripts
The scripts are divided into five sets:
Common variables and functions
Data setup
Main analyses
Simulation validation
Plotting
Script names have a three-digit prefix indicating their set (first digit) and running order.
Within each set, the x00 and x01 script contain common objects and functions respectively. This helps keep the code separate and clean.
1xx scripts: common
Common functions and a re-write of several gamlss functions (that had issues within our pipeline).
100.common-variables.r
- 101.common-functions.r
Create.Folders()
: Create folder structure for a specific subsetCheck.Attributes()
: Utility function for subsets of data
- 102.gamlss-recode.r
bfpNA()
: Custom version ofbfp()
that can handle `NA`sGGalt()
: Custom version ofGG()
(GAMLSS family) with robustGGalt$mean()
andGGalt$variance()
These scripts are sourced in later scripts, they define common variables/objects and functions.
Importantly, they also include a re-write of several gamlss functions to address numerical instability (these may not be necessary in a novel replication, however they are required for using our output fitted objects).
2xx scripts: data setup
Import and clean the data ready for the gamlss fitting. Also, generate simulated dataset (called omega) used for validation.
200.variables.r
- 201.functions.r
None
- 211.data-setup.r
Custom script to load and clean the raw data, outputs are
SUBSET.rds
and model objects
- 220.simulation-omega-setup.r
Custom script to create simulated data, outputs are
SUBSET.rds
and model objects
Each data script is a custom
3xx scripts:
These scripts perform the substantial calculations and model fitting.
300.variables.r
- 301.functions.r
Fit.Function()
: CallsExtract.Wrapper()
gamlssWrapper()
: Simple wrapper aroundgamlss()
to ensure consistent callsExtract.Summary()
: Generate consistent summary of subset/datasetExtract.Param()
: Create customParamObj
(new class of object) fromgamlss()
outputExtract.Wrapper()
: Combined call ofgamlssWrapper()
,Extract.Summary()
andExtract.Param()
Save.Extracted()
: Savegamlss()
output objects, called from withinFit.Function()
Make.bfpNA.model.from.extract()
: Convertfp()
intobfpNA()
, i.e. define fractional polynomial explicitlyFind.Models.To.Fit()
: Find candidate models under MODEL folderMake.Longitudinal()
: For longitudinal follow-up, generate subject-specific summary measures, e.g. IQRBoot.Function()
: Generate a bootstrap replicate dataset and callExtract.Wrapper()
ValidateCleanInput()
: Check dataset conforms toParamObj
Apply.Param()
: UseParamObj
to generate predictions for a dataset (callsValidateCleanInput()
)Apply.FitAndBoot()
: CallsApply.Param()
on all bootstrap replicateParamObj
Load.Subset.Wrapper()
: Load multiple elements intoHOLDER
objectCalc.Expanded()
: Wrapper callingRanef.MLE.Func()
andAdd.New.Ranefs()
Find.Fitted.Levels()
: CompareParamObj
with dataset to find studies with fitted random-effectsFind.Missing.Levels()
: CompareParamObj
with dataset to find studies with missing/unknown random-effectsRanef.MLE.Func()
: Estimate random-effects using maximum likelihood (using dXX from GAMLSS family)Add.New.Ranefs()
: Expand aParamObj
with new study random-effects
- 310.fitting.r
Uses
Fit.Function()
- 320.best-fit.r
Extracts BIC values from fitted models and selects the best (makes a copy or symlink as
MODEL.rds
)
- 330.bootstrapping.r
Uses
Boot.Function()
- 340.bootstrap-merge.r
Merges separate bootstrap outputs into
BOOT.EXTRACT.rds
- 350.calc-derived.r
Uses
Apply.Param()
andApply.FitandBoot()
to create all derived curves and outputs (for lifespan and study-specific curves) saved asDERIVED.rds
- 350.calc-novel.r
Uses
Calc.Expanded()
to estimate random-effects for novel data saved asFIT.EXPANDED.rds
(for fit and bootstrap replicates)
Main scripts, these fit the gamlss model(s), select the best (via BIC), perform bootstrapping, and calculate all necessary derived values.
5xx scripts: plotting
Some example plotting scripts using GNU R’s base graphics. The article uses “nicer” plots generated using ggplot2 (not included in this repository).
500.plotting-variables.r
- 501.plotting-functions.r
None
- 510.plotting.r
Example plots using
DERIVED.rds
object
Plotting functions, these only use the DERIVED.rds
and the fitted objects from novel data (FIT.EXPANDED.rds
).