Command line¶
The gen_surv command is a Typer
application. These are the functions behind its two subcommands; they can also
be called directly from Python.
cli
¶
Command-line interface for gen_surv.
This module provides a command-line interface for generating survival data using the gen_surv package.
dataset
¶
dataset(
model: str = Argument(
...,
help="Model to simulate [cphm, cmm, tdcm, thmm, aft_ln, aft_weibull, aft_log_logistic, competing_risks, competing_risks_weibull, mixture_cure, piecewise_exponential, recurrent_events]",
),
n: int = Option(100, help="Number of samples"),
model_cens: str = Option(
"uniform",
help="Censoring model: 'uniform' or 'exponential'",
),
cens_par: float = Option(
1.0, help="Censoring parameter"
),
beta: List[float] = Option(
[0.5],
help="Regression coefficient(s). Provide multiple values for multi-parameter models.",
),
covariate_range: float | None = Option(
2.0,
"--covariate-range",
"--covar",
help="Upper bound for covariate values (for CPHM, CMM, THMM)",
),
sigma: float | None = Option(
1.0,
help="Standard deviation parameter (for log-normal AFT)",
),
shape: float | None = Option(
1.5, help="Shape parameter (for Weibull AFT)"
),
scale: float | None = Option(
2.0, help="Scale parameter (for Weibull AFT)"
),
n_risks: int = Option(
2, help="Number of competing risks"
),
baseline_hazards: List[float] = Option(
[], help="Baseline hazards for competing risks"
),
shape_params: List[float] = Option(
[],
help="Shape parameters for Weibull competing risks",
),
scale_params: List[float] = Option(
[],
help="Scale parameters for Weibull competing risks",
),
cure_fraction: float | None = Option(
None, help="Cure fraction for mixture cure model"
),
baseline_hazard: float | None = Option(
None, help="Baseline hazard for mixture cure model"
),
breakpoints: List[float] = Option(
[],
help="Breakpoints for piecewise exponential model",
),
hazard_rates: List[float] = Option(
[],
help="Hazard rates for piecewise exponential model",
),
process: str = Option(
"ag",
help="Recurrent event process: 'ag' (Andersen-Gill), 'pwp_tt' or 'pwp_gt' (Prentice-Williams-Peterson in total or gap time)",
),
baseline: str = Option(
"exponential",
help="Baseline hazard for recurrent events: 'exponential', 'weibull' or 'gompertz'",
),
rate: List[float] = Option(
[],
help="Rate parameter(s). One value for recurrent events (exponential and Gompertz baselines); six for cmm and three for thmm, repeating the flag",
),
dist: str = Option(
"weibull",
help="Marginal distribution for tdcm: 'weibull' or 'exponential'",
),
corr: float = Option(
0.5,
help="Correlation between the covariate and the crossover time (tdcm)",
),
dist_par: List[float] = Option(
[],
help="Distribution parameters for tdcm: four values for 'weibull', two for 'exponential', repeating the flag",
),
lam: float = Option(
1.0, help="Baseline hazard rate for tdcm"
),
stratum_effects: List[float] = Option(
[],
help="Per-event intensity factors for the PWP recurrent processes",
),
max_events: int | None = Option(
None,
help="Stop following a subject after this many recurrent events",
),
followup_time: float = Option(
10.0,
help="Administrative end of follow-up for recurrent events",
),
seed: int | None = Option(
None, help="Random seed for reproducibility"
),
output: str | None = Option(
None,
"-o",
help="Output CSV file. Prints to stdout if omitted.",
),
) -> None
Generate survival data and optionally save to CSV.
Examples: # Generate data from CPHM model $ gen_surv dataset cphm --n 100 --beta 0.5 --covariate-range 2.0 -o cphm_data.csv
# Generate data from Weibull AFT model
$ gen_surv dataset aft_weibull --n 200 --beta 0.5 --beta -0.3 --shape 1.5 --scale 2.0 -o aft_data.csv
Source code in gen_surv/cli.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
visualize
¶
visualize(
input_file: str = Argument(
..., help="Input CSV file containing survival data"
),
time_col: str = Option(
"time",
help="Column containing time/duration values",
),
status_col: str = Option(
"status",
help="Column containing event indicator (1=event, 0=censored)",
),
group_col: str | None = Option(
None, help="Column to use for stratification"
),
output: str = Option(
"survival_plot.png", help="Output image file"
),
) -> None
Visualize survival data from a CSV file.
Examples: # Generate a Kaplan-Meier plot from a CSV file $ gen_surv visualize data.csv --time-col time --status-col status -o km_plot.png
# Generate a stratified plot using a grouping variable
$ gen_surv visualize data.csv --group-col X0 -o stratified_plot.png