Source: https://github.com/aipoch/medical-research-skills
Time-Dependent ROC Analysis
Use this skill to compute and plot time-dependent ROC curves for survival outcomes.
Use This Skill When
- You have survival data with
futime and fustat columns.
- You need time-specific ROC curves and AUC values for a numeric risk marker.
- You want a command-line workflow with parameter validation and standardized outputs.
- Your file contains a numeric marker column named
risk_score, or you will provide another marker explicitly with --marker_col.
Primary Command
Rscript scripts/main.R \
--data_file <input_file> \
--times <comma_separated_times> \
--output_dir <output_dir>
Prerequisites
Rscript is available in the shell.
- Required R packages:
optparse, timeROC, survival, ggplot2.
- Optional package for Excel input:
openxlsx.
- Install missing packages with
Rscript -e 'install.packages(c("optparse", "timeROC", "survival", "ggplot2", "openxlsx"), repos="https://cloud.r-project.org")'.
Core Arguments
| Argument |
Required |
Description |
--data_file |
Yes |
Input data file in CSV, TXT, TSV, TAB, XLS, or XLSX format |
--times |
No |
Prediction time points, comma-separated. Default 1,3,5 |
--marker_col |
No |
Marker column name. Default risk_score; provide this option when your file uses a different marker |
--output_dir |
No |
Output directory, default ./TimeROC_Results |
--time_unit |
No |
Time unit label for plot/output: year, month, or day. Default year |
--auto_convert_days |
No |
If TRUE, convert large futime values from days to the selected unit when appropriate. Default TRUE |
--weighting |
No |
IPCW weighting method: aalen, marginal, or cox. Default aalen |
--cause |
No |
Event code treated as the outcome of interest. Default 1 |
Input Requirements
- The input file must contain
futime and fustat columns.
- The selected marker column must exist and be numeric or coercible to numeric.
- If
--marker_col is omitted, the input file must contain risk_score.
futime must be numeric or coercible to numeric.
fustat must be numeric or coercible to numeric.
- Rows with missing
futime, fustat, or marker values are excluded.
- At least 5 complete rows and at least 1 event for the requested
cause are required.
Example input:
id fustat futime risk_score risk_group GPR161 RIBC2
TCGA-C5-A1M5 1 5.6219 -1.1070 low 2.8252 5.3532
TCGA-EA-A5O9 0 2.1589 -0.8964 low 2.6046 4.4293
TCGA-C5-A3HL 0 1.7014 -0.9044 low 4.1248 4.9166
Minimal Workflow
- Confirm the input file exists and includes
futime, fustat, and risk_score, or plan to pass --marker_col.
- Run
scripts/main.R with the requested time points.
- Check the output directory for the AUC table and PDF figure.
If you omit --data_file, the script exits with SKILL_MISSING_INPUT.
Outputs
Expected output structure:
<output_dir>/
├── data/
│ └── time_roc_points.<csv|txt>
├── session_info.txt
├── figure/
│ └── time_roc.pdf
└── table/
└── time_roc_auc.<csv|txt>
Primary output files:
data/time_roc_points.csv or data/time_roc_points.txt
table/time_roc_auc.csv or table/time_roc_auc.txt
figure/time_roc.pdf
session_info.txt
Exported result fields include:
time
time_unit
auc
marker_col
n_complete
n_events
Exported ROC point fields include:
false_positive_rate
sensitivity
time
time_unit
auc
curve_label
Read These Files When Needed
| Need |
File |
| Statistical details and assumptions |
references/algorithm.md |
| More CLI examples |
references/cli-guide.md |
| Error diagnosis |
references/troubleshooting.md |
| Main execution entry point |
scripts/main.R |
| Sample test data |
tests/data/ |
Quick Examples
Basic analysis:
Rscript scripts/main.R \
--data_file tests/data/time_roc_sample1.txt \
--times 1,3,5 \
--output_dir tests/output_basic
Specify marker column and plot styling:
Rscript scripts/main.R \
--data_file tests/data/time_roc_sample2.txt \
--marker_col GPR161 \
--times 1,2,4 \
--line_colors "#4DBBD5,#E64B35,#00A087" \
--legend_position bottom \
--output_dir tests/output_gpr161
Validation
Rscript scripts/main.R --help
Rscript scripts/main.R \
--data_file tests/data/time_roc_sample1.txt \
--times 1,3,5 \
--output_dir tests/validation_output
After running analysis, verify that these files exist:
tests/validation_output/data/time_roc_points.csv
tests/validation_output/table/time_roc_auc.csv
tests/validation_output/figure/time_roc.pdf
tests/validation_output/session_info.txt
Common Errors
SKILL_FILE_NOT_FOUND: Input file path is wrong or inaccessible.
SKILL_MISSING_COLUMNS: futime or fustat is missing.
SKILL_INVALID_DATA: The marker column is non-numeric, no complete rows remain, event coding is unsuitable, or requested time points yield unusable AUC values.
SKILL_INVALID_PARAMETER: An argument value is invalid.
SKILL_INSUFFICIENT_DATA: Too few complete rows or no target events remain.
SKILL_DEPENDENCY_MISSING: A required R package such as optparse, timeROC, survival, ggplot2, or openxlsx is unavailable.
If the issue is not obvious, read references/troubleshooting.md.
1---2name: time-dependent-roc3description: Use when performing time-dependent ROC curve analysis for survival data with follow-up time, event status, and a numeric marker. Supports CSV/TXT/TSV/Excel input, `risk_score` as the default marker unless `--marker_col` is provided, parameter validation, standardized output directories, AUC table export, ROC point export, and PDF figure generation.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8# Time-Dependent ROC Analysis
9
10Use this skill to compute and plot time-dependent ROC curves for survival outcomes.
11
12## Use This Skill When
13
14- You have survival data with `futime` and `fustat` columns.
15- You need time-specific ROC curves and AUC values for a numeric risk marker.
16- You want a command-line workflow with parameter validation and standardized outputs.
17- Your file contains a numeric marker column named `risk_score`, or you will provide another marker explicitly with `--marker_col`.
18
19## Primary Command
20
21```bash
22Rscript scripts/main.R \
23 --data_file <input_file> \
24 --times <comma_separated_times> \
25 --output_dir <output_dir>
26```
27
28## Prerequisites
29
30- `Rscript` is available in the shell.
31- Required R packages: `optparse`, `timeROC`, `survival`, `ggplot2`.
32- Optional package for Excel input: `openxlsx`.
33- Install missing packages with `Rscript -e 'install.packages(c("optparse", "timeROC", "survival", "ggplot2", "openxlsx"), repos="https://cloud.r-project.org")'`.
34
35## Core Arguments
36
37| Argument | Required | Description |
38|----------|----------|-------------|
39| `--data_file` | Yes | Input data file in CSV, TXT, TSV, TAB, XLS, or XLSX format |
40| `--times` | No | Prediction time points, comma-separated. Default `1,3,5` |
41| `--marker_col` | No | Marker column name. Default `risk_score`; provide this option when your file uses a different marker |
42| `--output_dir` | No | Output directory, default `./TimeROC_Results` |
43| `--time_unit` | No | Time unit label for plot/output: `year`, `month`, or `day`. Default `year` |
44| `--auto_convert_days` | No | If `TRUE`, convert large `futime` values from days to the selected unit when appropriate. Default `TRUE` |
45| `--weighting` | No | IPCW weighting method: `aalen`, `marginal`, or `cox`. Default `aalen` |
46| `--cause` | No | Event code treated as the outcome of interest. Default `1` |
47
48## Input Requirements
49
50- The input file must contain `futime` and `fustat` columns.
51- The selected marker column must exist and be numeric or coercible to numeric.
52- If `--marker_col` is omitted, the input file must contain `risk_score`.
53- `futime` must be numeric or coercible to numeric.
54- `fustat` must be numeric or coercible to numeric.
55- Rows with missing `futime`, `fustat`, or marker values are excluded.
56- At least 5 complete rows and at least 1 event for the requested `cause` are required.
57
58Example input:
59
60```text
61id fustat futime risk_score risk_group GPR161 RIBC2
62TCGA-C5-A1M5 1 5.6219 -1.1070 low 2.8252 5.3532
63TCGA-EA-A5O9 0 2.1589 -0.8964 low 2.6046 4.4293
64TCGA-C5-A3HL 0 1.7014 -0.9044 low 4.1248 4.9166
65```
66
67## Minimal Workflow
68
691. Confirm the input file exists and includes `futime`, `fustat`, and `risk_score`, or plan to pass `--marker_col`.
702. Run `scripts/main.R` with the requested time points.
713. Check the output directory for the AUC table and PDF figure.
72
73If you omit `--data_file`, the script exits with `SKILL_MISSING_INPUT`.
74
75## Outputs
76
77Expected output structure:
78
79```text
80<output_dir>/
81├── data/
82│ └── time_roc_points.<csv|txt>
83├── session_info.txt
84├── figure/
85│ └── time_roc.pdf
86└── table/
87 └── time_roc_auc.<csv|txt>
88```
89
90Primary output files:
91
92- `data/time_roc_points.csv` or `data/time_roc_points.txt`
93- `table/time_roc_auc.csv` or `table/time_roc_auc.txt`
94- `figure/time_roc.pdf`
95- `session_info.txt`
96
97Exported result fields include:
98
99- `time`
100- `time_unit`
101- `auc`
102- `marker_col`
103- `n_complete`
104- `n_events`
105
106Exported ROC point fields include:
107
108- `false_positive_rate`
109- `sensitivity`
110- `time`
111- `time_unit`
112- `auc`
113- `curve_label`
114
115## Read These Files When Needed
116
117| Need | File |
118|------|------|
119| Statistical details and assumptions | `references/algorithm.md` |
120| More CLI examples | `references/cli-guide.md` |
121| Error diagnosis | `references/troubleshooting.md` |
122| Main execution entry point | `scripts/main.R` |
123| Sample test data | `tests/data/` |
124
125## Quick Examples
126
127Basic analysis:
128
129```bash
130Rscript scripts/main.R \
131 --data_file tests/data/time_roc_sample1.txt \
132 --times 1,3,5 \
133 --output_dir tests/output_basic
134```
135
136Specify marker column and plot styling:
137
138```bash
139Rscript scripts/main.R \
140 --data_file tests/data/time_roc_sample2.txt \
141 --marker_col GPR161 \
142 --times 1,2,4 \
143 --line_colors "#4DBBD5,#E64B35,#00A087" \
144 --legend_position bottom \
145 --output_dir tests/output_gpr161
146```
147
148## Validation
149
150```bash
151Rscript scripts/main.R --help
152```
153
154```bash
155Rscript scripts/main.R \
156 --data_file tests/data/time_roc_sample1.txt \
157 --times 1,3,5 \
158 --output_dir tests/validation_output
159```
160
161After running analysis, verify that these files exist:
162
163- `tests/validation_output/data/time_roc_points.csv`
164- `tests/validation_output/table/time_roc_auc.csv`
165- `tests/validation_output/figure/time_roc.pdf`
166- `tests/validation_output/session_info.txt`
167
168## Common Errors
169
170- `SKILL_FILE_NOT_FOUND`: Input file path is wrong or inaccessible.
171- `SKILL_MISSING_COLUMNS`: `futime` or `fustat` is missing.
172- `SKILL_INVALID_DATA`: The marker column is non-numeric, no complete rows remain, event coding is unsuitable, or requested time points yield unusable AUC values.
173- `SKILL_INVALID_PARAMETER`: An argument value is invalid.
174- `SKILL_INSUFFICIENT_DATA`: Too few complete rows or no target events remain.
175- `SKILL_DEPENDENCY_MISSING`: A required R package such as `optparse`, `timeROC`, `survival`, `ggplot2`, or `openxlsx` is unavailable.
176
177If the issue is not obvious, read `references/troubleshooting.md`.