@fullstax/kaplan-meier-estimator
v3.1.2
Published
Kaplan-Meier-Estimator also known as the product limit estimator.
Downloads
54
Readme
kaplan-meier-estimator
A JavaScript implementation of the Kaplan-Meier-Estimator also known as the product limit estimator.
Installation
node
npm install --save kaplan-meier-estimator
Browser
<script src="https://unpkg.com/kaplan-meier-estimator@latest/lib/kaplan-meier-estimator.umd.js">
Usage
esm/typescript usage
See examples/node for an example implementation.
import { compute } from '@fullstax/kaplan-meier-estimator';
const timeToEvents = [1, 12, 22, 29, 31, …];
const events = [false, true, false, true, true, …];
const kmData = compute(timeToEvents, events);
console.table(kmData);
CommonJs is also supported:
const { compute } = require('@fullstax/kaplan-meier-estimator');
browser usage
See examples/browser for an example implementation. To server this example jsu start d webserver in the root of this repository.
<script src="https://unpkg.com/@fullstax/kaplan-meier-estimator/lib/kaplan-meier-estimator.umd.js">
const timeToEvents = [1, 12, 22, 29, 31, …];
const events = [false, true, false, true, true, …];
const kmData = KME.compute((timeToEvents, events);
console.table(kmData);
example output
┌─────────┬───────┬──────┬───────┐
│ (index) │ rate │ time │ event │
├─────────┼───────┼──────┼───────┤
│ 0 │ 1 │ 1 │ false │
│ 1 │ 0.929 │ 12 │ true │
│ 2 │ 0.929 │ 22 │ false │
│ 3 │ 0.851 │ 29 │ true │
│ 4 │ 0.774 │ 31 │ true │
│ … │ … │ … │ … │
└─────────┴───────┴──────┴───────┘
Example
Data
| # | Time to Event | event | > | S(t) | | --: | ------------: | :-------: | --- | ---: | | 1 | 1 | false | | 1 | | 2 | 12 | true | | 0.93 | | 3 | 22 | false | | 0.93 | | 4 | 29 | true | | 0.85 | | 5 | 31 | true | | 0.77 | | 6 | 36 | false | | 0.77 | | 7 | 38 | false | | 0.77 | | 8 | 50 | false | | 0.77 | | 9 | 60 | false | | 0.77 | | 10 | 61 | true | | 0.64 | | 11 | 70 | true | | 0.52 | | 12 | 88 | false | | 0.52 | | 13 | 99 | false | | 0.52 | | 14 | 110 | false | | 0.52 | | 15 | 140 | false | | 0.52 |
Plot
License
Licensed 2022 by fullstax GmbH & Co. KG under a MIT License.