Survival
Estimate survival curves, hazard ratios and log-rank tests from time-to-event data
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/survival/index.md to help me query Survival with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Estimate a survival curve over time
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time
| time | survival | at_risk |
|---|---|---|
| 0 | 1 | 5 |
| 3 | 0.8 | 5 |
| 5 | 0.6 | 4 |
| 8 | 0.6 | 3 |
| 9 | 0.6 | 2 |
Quick start
Choose where to run Survival, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'survival' AS survival (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-survival-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'survival' AS survival (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-survival:0.5.0'
);
3. Run a query
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'survival' AS survival
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time
Query Farm operates Survival for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use survival as the catalog alias for the query below.
4. Run a query
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'survival' AS survival (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-survival-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'survival' AS survival (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-survival:0.5.0'
);
Overview
Survival / time-to-event analysis (Kaplan-Meier, Cox PH, log-rank, median survival) for SQL.

Run Kaplan-Meier survival curves, Cox proportional-hazards regression, and the log-rank test directly in DuckDB SQL — no Python notebook, no data export, no glue code. The survival catalog brings rigorous time-to-event statistics to your data warehouse over Apache Arrow.
What it does
Survival analysis answers time-until-something-happens questions: how long until a patient relapses, a customer churns, a machine fails, or a subscription lapses. This extension takes a cohort of subjects — each with a follow-up duration and a 0/1 event indicator (1 = the event of interest occurred, 0 = the subject was right-censored, i.e. still event-free when observation ended) — and computes the standard estimators of survival analysis, all from a SQL query. It is built for analysts, data scientists, and engineers working on clinical trials, customer churn and retention, hardware reliability, and any cohort whose outcome is time until an event.
How it works
Every estimator is powered by lifelines, the widely used, MIT-licensed Python survival-analysis library (see the lifelines documentation). The worker buffers the entire input relation, hands it to the appropriate lifelines estimator once, and streams the result back as Arrow rows — so the numbers match lifelines exactly. Every function is a table function: it consumes a whole (SELECT ...) relation as its first argument, and you name which columns play which role using named string arguments such as duration := 't' and event := 'e'.
When to reach for it
Reach for the survival catalog whenever your question is time until an event and your data has a follow-up duration plus a 0/1 censoring indicator: charting how an event-free population decays over time, quantifying how covariates raise or lower risk, testing whether two arms differ, or reducing a cohort to a single headline survival number. It fits Kaplan-Meier curves, Cox proportional-hazards regression, and the log-rank test.
Notes
Event coding is 1/true = event occurred, 0/false = right-censored — get this backwards and every curve and hazard ratio inverts. Cox treats every column besides duration/event as a covariate, so select exactly the covariate columns you want. Because group is a SQL keyword, double-quote it at the logrank_test call site: "group" := 'arm'.
Catalog
Everything survival exposes once attached — read straight from the worker's
released build.
main 1 view · 4 functions
Survival / time-to-event analysis (Kaplan-Meier, Cox PH, log-rank) for SQL
Schema examples (7)
Kaplan-Meier survival curve for a small cohort, projected and ordered by time
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time;
| time | survival | at_risk |
|---|---|---|
| 0 | 1 | 5 |
| 3 | 0.8 | 5 |
| 5 | 0.6 | 4 |
| 8 | 0.6 | 3 |
| 9 | 0.6 | 2 |
Cox hazard ratio and Wald p-value for a single covariate
SELECT covariate, hazard_ratio, p_value
FROM survival.main.cox_hazard_ratios((SELECT * FROM (VALUES (5,1,1.0),(8,0,0.0),(12,1,2.0),(3,1,3.0),(9,0,0.0),(6,1,1.0)) AS c(t, e, prio)), duration := 't', event := 'e')
ORDER BY covariate;
Log-rank test comparing survival between two treatment arms
SELECT test_statistic, p_value, degrees_freedom
FROM survival.main.logrank_test((SELECT * FROM (VALUES (5,1,'a'),(8,0,'a'),(12,1,'b'),(3,1,'b'),(9,0,'a'),(6,1,'b')) AS c(t, e, arm)), duration := 't', event := 'e', "group" := 'arm');
Median survival time as a single headline number
SELECT median_survival
FROM survival.main.median_survival((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e');
3 more examples
Treatment-effect headline for a two-arm trial: the log-rank p-value comparing the arms next to the Cox hazard ratio (with 95% CI and Wald p-value) of treated vs control, one row from the same cohort
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT round(lr.p_value, 4) AS logrank_p_value, round(cx.hazard_ratio, 3) AS hazard_ratio, round(cx.ci_lower, 3) AS hr_ci_lower, round(cx.ci_upper, 3) AS hr_ci_upper, round(cx.p_value, 4) AS cox_p_value
FROM survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
CROSS JOIN survival.main.cox_hazard_ratios((SELECT t, e, (arm = 'treated')::INTEGER AS treated FROM cohort), duration := 't', event := 'e') AS cx
ORDER BY cx.covariate;
Median survival time of each trial arm side by side with the log-rank p-value testing whether the arms differ (control 6.0, treated 15.0, p = 0.0199)
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT mc.median_survival AS median_control, mt.median_survival AS median_treated, round(lr.p_value, 4) AS logrank_p_value
FROM survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS mc
CROSS JOIN survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS mt
CROSS JOIN survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
ORDER BY median_control;
Landmark survival table: each arm's Kaplan-Meier survival probability at t = 6 and t = 12, read off the step curves with an ASOF join
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)), landmarks AS (SELECT * FROM (VALUES (6.0), (12.0)) AS l(landmark)) SELECT l.landmark, round(kc.survival, 3) AS control_survival, round(kt.survival, 3) AS treated_survival
FROM landmarks AS l
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS kc ON kc.time <= l.landmark
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS kt ON kt.time <= l.landmark
ORDER BY l.landmark;
methods
Registry of the survival table functions this catalog exposes (method, category, question, returns).
List every regression method with the question it answers
SELECT method, question, returns
FROM survival.main.methods
WHERE category = 'regression'
ORDER BY method;
Count the available survival methods per category
SELECT category, count(*) AS n_methods
FROM survival.main.methods
GROUP BY category
ORDER BY category;
cox_hazard_ratios (data TABLE, duration := VARCHAR, event := VARCHAR)
Cox proportional-hazards model. Every column besides duration/event is a covariate; emits (covariate, coef, hazard_ratio, ci_lower, ci_upper, p_value).
Cox hazard ratio and Wald p-value for each covariate
SELECT covariate, hazard_ratio, p_value
FROM survival.main.cox_hazard_ratios((SELECT * FROM (VALUES (5,1,1.0),(8,0,0.0),(12,1,2.0),(3,1,3.0),(9,0,0.0),(6,1,1.0)) AS c(t, e, prio)), duration := 't', event := 'e')
ORDER BY covariate;
Treatment-effect headline for a two-arm trial: the log-rank p-value comparing the arms next to the Cox hazard ratio (with 95% CI and Wald p-value) of treated vs control, one row from the same cohort
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT round(lr.p_value, 4) AS logrank_p_value, round(cx.hazard_ratio, 3) AS hazard_ratio, round(cx.ci_lower, 3) AS hr_ci_lower, round(cx.ci_upper, 3) AS hr_ci_upper, round(cx.p_value, 4) AS cox_p_value
FROM survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
CROSS JOIN survival.main.cox_hazard_ratios((SELECT t, e, (arm = 'treated')::INTEGER AS treated FROM cohort), duration := 't', event := 'e') AS cx
ORDER BY cx.covariate;
kaplan_meier (data TABLE, duration := VARCHAR, event := VARCHAR)
Kaplan-Meier survival curve: (time, survival, ci_lower, ci_upper, at_risk). event=1/true means the event occurred; 0/false means censored.
Kaplan-Meier survival curve projected to the survival probability and at-risk count
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
ORDER BY time;
| time | survival | at_risk |
|---|---|---|
| 0 | 1 | 5 |
| 3 | 0.8 | 5 |
| 5 | 0.6 | 4 |
| 8 | 0.6 | 3 |
| 9 | 0.6 | 2 |
Landmark survival table: each arm's Kaplan-Meier survival probability at t = 6 and t = 12, read off the step curves with an ASOF join
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)), landmarks AS (SELECT * FROM (VALUES (6.0), (12.0)) AS l(landmark)) SELECT l.landmark, round(kc.survival, 3) AS control_survival, round(kt.survival, 3) AS treated_survival
FROM landmarks AS l
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS kc ON kc.time <= l.landmark
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS kt ON kt.time <= l.landmark
ORDER BY l.landmark;
SELECT time, survival, at_risk
FROM survival.main.kaplan_meier((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
WHERE time = 3;
logrank_test (data TABLE, duration := VARCHAR, event := VARCHAR, group := VARCHAR)
Log-rank test comparing survival across the group column; emits one row (test_statistic, p_value, degrees_freedom).
Log-rank statistic and p-value comparing two treatment arms
SELECT test_statistic, p_value, degrees_freedom
FROM survival.main.logrank_test((SELECT * FROM (VALUES (5,1,'a'),(8,0,'a'),(12,1,'b'),(3,1,'b'),(9,0,'a'),(6,1,'b')) AS c(t, e, arm)), duration := 't', event := 'e', "group" := 'arm');
Treatment-effect headline for a two-arm trial: the log-rank p-value comparing the arms next to the Cox hazard ratio (with 95% CI and Wald p-value) of treated vs control, one row from the same cohort
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT round(lr.p_value, 4) AS logrank_p_value, round(cx.hazard_ratio, 3) AS hazard_ratio, round(cx.ci_lower, 3) AS hr_ci_lower, round(cx.ci_upper, 3) AS hr_ci_upper, round(cx.p_value, 4) AS cox_p_value
FROM survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
CROSS JOIN survival.main.cox_hazard_ratios((SELECT t, e, (arm = 'treated')::INTEGER AS treated FROM cohort), duration := 't', event := 'e') AS cx
ORDER BY cx.covariate;
Median survival time of each trial arm side by side with the log-rank p-value testing whether the arms differ (control 6.0, treated 15.0, p = 0.0199)
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT mc.median_survival AS median_control, mt.median_survival AS median_treated, round(lr.p_value, 4) AS logrank_p_value
FROM survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS mc
CROSS JOIN survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS mt
CROSS JOIN survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
ORDER BY median_control;
median_survival (data TABLE, duration := VARCHAR, event := VARCHAR)
Median survival time (Kaplan-Meier S(t)=0.5) as a single row; inf if the curve never reaches 0.5.
Median survival time for a small cohort
SELECT median_survival
FROM survival.main.median_survival((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e');
Median survival time of each trial arm side by side with the log-rank p-value testing whether the arms differ (control 6.0, treated 15.0, p = 0.0199)
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT mc.median_survival AS median_control, mt.median_survival AS median_treated, round(lr.p_value, 4) AS logrank_p_value
FROM survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS mc
CROSS JOIN survival.main.median_survival((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS mt
CROSS JOIN survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
ORDER BY median_control;
Try these queries
Cox hazard ratio and Wald p-value for a single covariate
SELECT covariate, hazard_ratio, p_value
FROM survival.main.cox_hazard_ratios((SELECT * FROM (VALUES (5,1,1.0),(8,0,0.0),(12,1,2.0),(3,1,3.0),(9,0,0.0),(6,1,1.0)) AS c(t, e, prio)), duration := 't', event := 'e')
ORDER BY covariate
Uses cox_hazard_ratios
Log-rank test comparing survival between two treatment arms
SELECT test_statistic, p_value, degrees_freedom
FROM survival.main.logrank_test((SELECT * FROM (VALUES (5,1,'a'),(8,0,'a'),(12,1,'b'),(3,1,'b'),(9,0,'a'),(6,1,'b')) AS c(t, e, arm)), duration := 't', event := 'e', "group" := 'arm')
Uses logrank_test
Median survival time as a single headline number
SELECT median_survival
FROM survival.main.median_survival((SELECT * FROM (VALUES (5,1),(8,0),(12,1),(3,1),(9,0)) AS c(t, e)), duration := 't', event := 'e')
Uses median_survival
Treatment-effect headline for a two-arm trial: the log-rank p-value comparing the arms next to the Cox hazard ratio (with 95% CI and Wald p-value) of treated vs control, one row from the same cohort
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)) SELECT round(lr.p_value, 4) AS logrank_p_value, round(cx.hazard_ratio, 3) AS hazard_ratio, round(cx.ci_lower, 3) AS hr_ci_lower, round(cx.ci_upper, 3) AS hr_ci_upper, round(cx.p_value, 4) AS cox_p_value
FROM survival.main.logrank_test((SELECT t, e, arm FROM cohort), duration := 't', event := 'e', "group" := 'arm') AS lr
CROSS JOIN survival.main.cox_hazard_ratios((SELECT t, e, (arm = 'treated')::INTEGER AS treated FROM cohort), duration := 't', event := 'e') AS cx
ORDER BY cx.covariate
Landmark survival table: each arm's Kaplan-Meier survival probability at t = 6 and t = 12, read off the step curves with an ASOF join
WITH cohort AS (SELECT * FROM (VALUES (2,1,'control'),(3,1,'control'),(4,1,'control'),(5,0,'control'),(6,1,'control'),(8,1,'control'),(9,0,'control'),(11,1,'control'),(4,1,'treated'),(7,0,'treated'),(9,1,'treated'),(12,1,'treated'),(14,0,'treated'),(15,1,'treated'),(18,1,'treated'),(20,0,'treated')) AS c(t, e, arm)), landmarks AS (SELECT * FROM (VALUES (6.0), (12.0)) AS l(landmark)) SELECT l.landmark, round(kc.survival, 3) AS control_survival, round(kt.survival, 3) AS treated_survival
FROM landmarks AS l
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'control'), duration := 't', event := 'e') AS kc ON kc.time <= l.landmark
ASOF JOIN survival.main.kaplan_meier((SELECT t, e FROM cohort WHERE arm = 'treated'), duration := 't', event := 'e') AS kt ON kt.time <= l.landmark
ORDER BY l.landmark
Uses kaplan_meier
List every regression method with the question it answers
SELECT method, question, returns
FROM survival.main.methods
WHERE category = 'regression'
ORDER BY method
Uses methods
3 more examples in the Catalog, each listed under the table or function it uses.
Survival is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Anomaly
Statistics & ML
Find outliers, discords, repeated motifs and change points in numeric series from SQL
Causal
Statistics & ML
Estimate treatment effects (ATE, ATT) and propensity scores from observational data with IPW, regression adjustment, and AIPW
Explain
Statistics & ML
Explain scikit-learn and XGBoost model predictions with per-row SHAP values and global feature importance