Skip to content
Back to skills

Estimate Additional Survival Time Conditional

ASecurity

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.

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
ai-agents

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill estimate_additional_survival_time_conditional --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Estimate Additional Survival Time Conditional?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Estimate Additional Survival Time Conditional
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-estimate-additional-survival-time-conditional/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-estimate-additional-survival-time-conditional)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "5efbd249-523d-44df-8946-6197d1bd0a05"
name: "estimate_additional_survival_time_conditional"
description: "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."
version: "0.1.1"
tags:
  - "R"
  - "survival analysis"
  - "Cox model"
  - "conditional probability"
  - "weighted average"
triggers:
  - "estimate additional survival time"
  - "weighted average survival time"
  - "conditional survival probability"
  - "cox model expected time"
  - "predict remaining lifetime"
---

# 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
1. **Model Fitting**: Fit a Cox model using `coxph(Surv(time, status) ~ covariates, data = data)`.
2. **Prediction**: Calculate linear predictors for alive patients using `predict()`.
3. **Baseline Survival**: Generate the baseline survival curve using `survfit()`.
4. **Adjusted Probabilities**: Calculate adjusted cumulative survival probabilities for each alive patient by multiplying baseline survival probabilities by `exp(linear_predictor)`.
5. **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).
6. **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))`.
7. **Weighted Average**: Calculate the expected survival time as the weighted average of the future time points, using the conditional survival probabilities as weights.
8. **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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.