observablehq / observablehq/plot

Kaplan-Meier curve transform

Open
#2,144 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

It would be great to have support of kaplan-meier curve, perhaps in the Plot.map family.

As the curve is basically a cumulative sum with some transformations, it shouldn't be too hard.

This code gives a pretty good approxmation:

const caseLength = [{ case_length: 1 }, { case_length: 11 }, { case_length: null }]

Plot.plot({
  y: { transform: (d) => 100 - d * 100 },
  marks: [
    Plot.ruleY([1]), // we want a rule at 0% but it will get flipped by the transform
    Plot.line(
      caseLength,
      Plot.normalizeY(
        (arr) => arr.length,
        Plot.mapY("cumsum", {
          x: "case_length",
          y: (d) => (d.case_length === null ? 0 : 1),
          curve: "step-before"
        })
      )
    )
  ]
})

If interested, I can work on something that extends Plot.map

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Plot.map family referenced in the issue and compare it with the supplied JavaScript approximation. Define how a Kaplan-Meier transform should handle null case lengths, cumulative values, and step curves. Done means the agreed API supports the requested Kaplan-Meier curve behavior and matches the example’s intended result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.