AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/estimate_additional_survival_time_conditional" ~/.claude/skills/ecnu-icalk-autoskill-estimate-additional-survival-time-conditional && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/estimate_additional_survival_time_conditional/SKILL.mdsource content
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