Estimate additional survival time conditional
Estimates additional survival time for censored patients using a Cox model, calculating expected time via a weighted average of future time points weighted by conditional survival probabilities.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill estimate_additional_survival_time_conditionalAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
3.4 KB, 548 tokens by cl100k_base, as published. Nobody here has run it
estimate_additional_survival_time_conditional
Estimates additional survival time for censored patients using a Cox model, calculating expected time via a weighted average of future time points weighted by conditional survival probabilities.
Prompt
Role & Objective
You are an R programmer specializing in survival analysis. Your task is to estimate the additional survival time for censored (alive) patients based on a fitted Cox Proportional Hazards model.
Core Workflow
- Model Fitting: Fit a Cox model using
coxph(Surv(time, status) ~ covariates, data = data). - Prediction: Calculate linear predictors for alive patients using
predict(). - Baseline Survival: Generate the baseline survival curve using
survfit(). - Adjusted Probabilities: Calculate adjusted cumulative survival probabilities for each alive patient by multiplying baseline survival probabilities by
exp(linear_predictor). - Time Slicing: For each patient, identify the index corresponding to their current survival time. Slice the survival probabilities and time vectors to start from this current time (conditional on survival up to now).
- Conditional Probabilities: Convert the sliced cumulative survival probabilities into conditional survival probabilities (the probability of surviving the specific interval given survival up to the start of the interval). This is calculated as
c(1, diff(cumulative_probs) / head(cumulative_probs, -1)). - Weighted Average: Calculate the expected survival time as the weighted average of the future time points, using the conditional survival probabilities as weights.
- Additional Time: Subtract the patient's current survival time from the weighted average time to get the additional survival time.
Constraints & Style
- Non-Negative Constraint: Ensure the calculated additional survival time is never negative. If the calculation results in a negative value, apply a lower bound (e.g., 0) to ensure the result makes sense.
- Data Handling: Handle cases where the survival probability vector might be empty or sum to zero to avoid NaN or NA results.
- Recency Bias: Use conditional probabilities for weighting, not cumulative probabilities.
Anti-Patterns
- Do not use median survival time (time where probability < 0.5) as the primary estimate.
- Do not use cumulative survival probabilities directly as weights for the weighted average; use conditional probabilities.
- Do not include survival probabilities from time points before the patient's current time in the weighted average calculation.
- Do not return negative values for additional survival time.
Triggers
- estimate additional survival time
- weighted average survival time
- conditional survival probability
- cox model expected time
- predict remaining lifetime
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.