# thehanlab/dynamiclm architecture

> Architecture diagram of the GitHub repository thehanlab/dynamiclm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thehanlab/dynamiclm
- Repository: https://github.com/thehanlab/dynamiclm

## Overview

dynamicLM is an R package for dynamic survival-risk prediction: it prepares cohort data, fits landmark supermodels, predicts updated risks, and evaluates or visualizes results. The README documents the principal workflow and capabilities, but no source excerpts were provided; edges therefore reflect documented relationships, not inspected function calls.

Main entry points: [`R/predict.R`](https://github.com/thehanlab/dynamiclm/blob/main/R/predict.R) (Risk prediction), [`R/stack_data.R`](https://github.com/thehanlab/dynamiclm/blob/main/R/stack_data.R) (Stacked data), [`R/score.R`](https://github.com/thehanlab/dynamiclm/blob/main/R/score.R) (Prediction scoring), [`R/get_pbc_long.R`](https://github.com/thehanlab/dynamiclm/blob/main/R/get_pbc_long.R) (PBC loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_pbc["PBC loader<br/>[get_pbc_long.R]"]
  node_stack["Stacked data<br/>[stack_data.R]"]
  node_interactions["Time interactions<br/>[add_interactions.R]"]
  node_data_helpers["Model data<br/>[get_lm_data.R]"]
end

subgraph group_models["Landmark modeling"]
  node_landmark_model["Landmark model<br/>[dynamic_lm.R]"]
  node_penalized_model["Penalized model<br/>[pen_lm.R]"]
  node_cross_validation["Cross-validation<br/>[cv.pen_lm.R]"]
  node_model_helpers["Model helpers"]
end

subgraph group_prediction["Risk prediction"]
  node_risk_prediction["Risk prediction<br/>[predict.R]"]
  node_risk_score["Risk scores<br/>[riskScore.R]"]
end

subgraph group_evaluation["Evaluation and plots"]
  node_scoring["Prediction scoring<br/>[score.R]"]
  node_metrics["Performance metrics<br/>[summary_metric.R]"]
  node_calibration["Calibration plots<br/>[calplot.R]"]
  node_risk_plot["Risk trajectories<br/>[plotrisk.R]"]
  node_plots["Model plots<br/>[plot.R]"]
end

node_analyst(("Analyst"))
node_cohort["Survival data"]

node_analyst -->|"loads data"| node_pbc
node_cohort -->|"combines data"| node_pbc
node_analyst -->|"prepares cohort"| node_stack
node_stack -->|"fits on"| node_landmark_model
node_stack -->|"fits on"| node_penalized_model
node_analyst -->|"validates model"| node_cross_validation
node_analyst -->|"predicts risk"| node_risk_prediction
node_risk_prediction -->|"evaluates predictions"| node_scoring
node_risk_prediction -->|"checks calibration"| node_calibration
node_risk_prediction -->|"visualizes trajectories"| node_risk_plot
node_risk_prediction -->|"visualizes model"| node_plots
node_scoring -->|"reports metrics"| node_metrics

click node_pbc "https://github.com/thehanlab/dynamiclm/blob/main/R/get_pbc_long.R"
click node_stack "https://github.com/thehanlab/dynamiclm/blob/main/R/stack_data.R"
click node_interactions "https://github.com/thehanlab/dynamiclm/blob/main/R/add_interactions.R"
click node_data_helpers "https://github.com/thehanlab/dynamiclm/blob/main/R/get_lm_data.R"
click node_landmark_model "https://github.com/thehanlab/dynamiclm/blob/main/R/dynamic_lm.R"
click node_penalized_model "https://github.com/thehanlab/dynamiclm/blob/main/R/pen_lm.R"
click node_cross_validation "https://github.com/thehanlab/dynamiclm/blob/main/R/cv.pen_lm.R"
click node_model_helpers "https://github.com/thehanlab/dynamiclm/blob/main/R/dynamic_lm_helper.R"
click node_risk_prediction "https://github.com/thehanlab/dynamiclm/blob/main/R/predict.R"
click node_risk_score "https://github.com/thehanlab/dynamiclm/blob/main/R/riskScore.R"
click node_scoring "https://github.com/thehanlab/dynamiclm/blob/main/R/score.R"
click node_metrics "https://github.com/thehanlab/dynamiclm/blob/main/R/summary_metric.R"
click node_calibration "https://github.com/thehanlab/dynamiclm/blob/main/R/calplot.R"
click node_risk_plot "https://github.com/thehanlab/dynamiclm/blob/main/R/plotrisk.R"
click node_plots "https://github.com/thehanlab/dynamiclm/blob/main/R/plot.R"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pbc,node_stack,node_interactions,node_data_helpers toneBlue
class node_landmark_model,node_penalized_model,node_cross_validation,node_model_helpers toneAmber
class node_risk_prediction,node_risk_score toneMint
class node_scoring,node_metrics,node_calibration,node_risk_plot,node_plots toneRose
class node_analyst,node_cohort toneIndigo
```

## Components

### Data preparation

- [PBC loader](https://github.com/thehanlab/dynamiclm/blob/main/R/get_pbc_long.R): `R/get_pbc_long.R`
- [Stacked data](https://github.com/thehanlab/dynamiclm/blob/main/R/stack_data.R): `R/stack_data.R`
- [Time interactions](https://github.com/thehanlab/dynamiclm/blob/main/R/add_interactions.R): `R/add_interactions.R`
- [Model data](https://github.com/thehanlab/dynamiclm/blob/main/R/get_lm_data.R): `R/get_lm_data.R`

### Landmark modeling

- [Landmark model](https://github.com/thehanlab/dynamiclm/blob/main/R/dynamic_lm.R): `R/dynamic_lm.R`
- [Penalized model](https://github.com/thehanlab/dynamiclm/blob/main/R/pen_lm.R): `R/pen_lm.R`
- [Cross-validation](https://github.com/thehanlab/dynamiclm/blob/main/R/cv.pen_lm.R): `R/cv.pen_lm.R`
- [Model helpers](https://github.com/thehanlab/dynamiclm/blob/main/R/dynamic_lm_helper.R): `R/dynamic_lm_helper.R`

### Risk prediction

- [Risk prediction](https://github.com/thehanlab/dynamiclm/blob/main/R/predict.R): `R/predict.R`
- [Risk scores](https://github.com/thehanlab/dynamiclm/blob/main/R/riskScore.R): `R/riskScore.R`

### Evaluation and plots

- [Prediction scoring](https://github.com/thehanlab/dynamiclm/blob/main/R/score.R): `R/score.R`
- [Performance metrics](https://github.com/thehanlab/dynamiclm/blob/main/R/summary_metric.R): `R/summary_metric.R`
- [Calibration plots](https://github.com/thehanlab/dynamiclm/blob/main/R/calplot.R): `R/calplot.R`
- [Risk trajectories](https://github.com/thehanlab/dynamiclm/blob/main/R/plotrisk.R): `R/plotrisk.R`
- [Model plots](https://github.com/thehanlab/dynamiclm/blob/main/R/plot.R): `R/plot.R`

### Other components

- **Analyst**
- **Survival data**

## Connections

- Analyst → PBC loader: loads data (evidence: `README.md`)
- Survival data → PBC loader: combines data (evidence: `README.md`)
- Analyst → Stacked data: prepares cohort (evidence: `README.md`)
- Stacked data → Landmark model: fits on (evidence: `README.md`)
- Stacked data → Penalized model: fits on (evidence: `README.md`)
- Analyst → Cross-validation: validates model (evidence: `README.md`)
- Analyst → Risk prediction: predicts risk (evidence: `README.md`)
- Risk prediction → Prediction scoring: evaluates predictions (evidence: `README.md`)
- Risk prediction → Calibration plots: checks calibration (evidence: `README.md`)
- Risk prediction → Risk trajectories: visualizes trajectories (evidence: `README.md`)
- Risk prediction → Model plots: visualizes model (evidence: `README.md`)
- Prediction scoring → Performance metrics: reports metrics (evidence: `README.md`)
