Mostrar supervivencia con su curva de combinación y métodos por estimación
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
|
||||
/** One entry of the survival report's `km_combinaciones`: the patients who share every value. */
|
||||
export interface Combination {
|
||||
valores: Record<string, string>;
|
||||
n: number;
|
||||
fallecidos: number;
|
||||
km?: { months: number[]; S: number[]; low: number[]; high: number[] };
|
||||
}
|
||||
|
||||
/** The entry with exactly her values (a missing one is the report's "NA"); never a partial match. */
|
||||
export function combinationOf(
|
||||
report: Record<string, unknown> | null | undefined,
|
||||
inputs: Record<string, unknown>,
|
||||
): Combination | undefined {
|
||||
const all = report?.['km_combinaciones'];
|
||||
return (Array.isArray(all) ? (all as Combination[]) : []).find((c) => {
|
||||
const keys = Object.keys(c.valores);
|
||||
return (
|
||||
keys.length === Object.keys(inputs).length &&
|
||||
keys.every((k) => k in inputs && c.valores[k] === String(inputs[k] ?? 'NA'))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/** Why there is no curve for her: these are not the same thing, so each is said apart. (A patient
|
||||
* outside the survival scenario has no survival section at all.) */
|
||||
export function noCurveText(
|
||||
report: Record<string, unknown> | null | undefined,
|
||||
found: Combination | undefined,
|
||||
): string {
|
||||
if (!Array.isArray(report?.['km_combinaciones']))
|
||||
return 'No disponible: la versión del modelo que la evaluó no publica esta curva.';
|
||||
const minimum = report['min_fallecidos_escenario'];
|
||||
const counts = `n = ${found?.n ?? 0}, fallecidos = ${found?.fallecidos ?? 0}`;
|
||||
return `No disponible: datos insuficientes para su combinación de valores (${counts}${
|
||||
typeof minimum === 'number' ? `; mínimo requerido: ${minimum} fallecidos` : ''
|
||||
}).`;
|
||||
}
|
||||
|
||||
export function combinationFigure(km: NonNullable<Combination['km']>): Figure {
|
||||
const line = (y: number[], more: object) => ({
|
||||
type: 'scatter',
|
||||
mode: 'lines',
|
||||
x: km.months,
|
||||
y,
|
||||
line: { shape: 'hv', color: PALETTE[0], width: 0 },
|
||||
...more,
|
||||
});
|
||||
return {
|
||||
data: [
|
||||
line(km.low, { showlegend: false, hoverinfo: 'skip' }),
|
||||
line(km.high, { name: 'IC 95 %', fill: 'tonexty', fillcolor: 'rgba(23, 50, 77, 0.15)' }),
|
||||
line(km.S, { name: 'Kaplan-Meier', line: { shape: 'hv', color: PALETTE[0], width: 2 } }),
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Meses desde el índice' } },
|
||||
yaxis: { title: { text: 'Supervivencia S(t)' }, range: [0, 1.02], tickformat: '.0%' },
|
||||
},
|
||||
} as Figure;
|
||||
}
|
||||
Reference in New Issue
Block a user