Follow ______ on twitter.

9.1.1 Introduction to survival analysis and hazard rates

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Survival Function, Hazard Rate, and Cumulative Hazard Rate Visualization",
  "hconcat": [
    {
      "width": 200,
      "height": 200,
      "data": {
        "sequence": {
          "start": 0,
          "stop": 60,
          "step": 1,
          "as": "time"
        }
      },
      "transform": [
        {
          "calculate": "exp(-0.00427 * datum.time)",
          "as": "survivalRate"
        }
      ],
      "mark": {
        "type": "line",
        "point": true
      },
      "encoding": {
        "x": {
          "field": "time",
          "type": "quantitative",
          "title": "Time (months)",
          "axis": {
            "tickCount": 6
          }
        },
        "y": {
          "field": "survivalRate",
          "type": "quantitative",
          "title": "Survival Rate",
          "axis": {
            "format": ".0%"
          },
          "scale": {
            "zero": false
          }
        },
        "tooltip": [
          {
            "field": "time",
            "type": "quantitative",
            "title": "Time (months)"
          },
          {
            "field": "survivalRate",
            "type": "quantitative",
            "title": "Survival Rate"
          }
        ]
      },
      "title": "Survival Rate"
    },
    {
      "width": 200,
      "height": 200,
      "data": {
        "sequence": {
          "start": 0,
          "stop": 60,
          "step": 1,
          "as": "time"
        }
      },
      "transform": [
        {
          "calculate": "0.00427",
          "as": "hazardRate"
        }
      ],
      "mark": {
        "type": "line",
        "point": true
      },
      "encoding": {
        "x": {
          "field": "time",
          "type": "quantitative",
          "title": "Time (months)",
          "axis": {
            "tickCount": 6
          }
        },
        "y": {
          "field": "hazardRate",
          "type": "quantitative",
          "title": "Hazard Rate",
          "axis": {
            "format": ".0%"
          },
          "scale": {
            "zero": false
          }
        },
        "tooltip": [
          {
            "field": "time",
            "type": "quantitative",
            "title": "Time (months)"
          },
          {
            "field": "hazardRate",
            "type": "quantitative",
            "title": "Hazard Rate"
          }
        ]
      },
      "title": "Hazard Rate"
    },
    {
      "width": 200,
      "height": 200,
      "data": {
        "sequence": {
          "start": 0,
          "stop": 60,
          "step": 1,
          "as": "time"
        }
      },
      "transform": [
        {
          "calculate": "datum.time * 0.00427",
          "as": "cumulativeHazard"
        }
      ],
      "mark": {
        "type": "line",
        "point": true
      },
      "encoding": {
        "x": {
          "field": "time",
          "type": "quantitative",
          "title": "Time (months)",
          "axis": {
            "tickCount": 6
          }
        },
        "y": {
          "field": "cumulativeHazard",
          "type": "quantitative",
          "title": "Cumulative Hazard",
          "axis": {
            "format": ".2f"
          },
          "scale": {
            "zero": false
          }
        },
        "tooltip": [
          {
            "field": "time",
            "type": "quantitative",
            "title": "Time (months)"
          },
          {
            "field": "cumulativeHazard",
            "type": "quantitative",
            "title": "Cumulative Hazard"
          }
        ]
      },
      "title": "Cumulative Hazard Rate"
    }
  ]
}