.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/reliability/lifetimes/plot_01_halley_life_table.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_reliability_lifetimes_plot_01_halley_life_table.py: Halley's life table and the hazard rate (1693) ============================================== In 1693 Edmond Halley used five years of births and burials from Breslau to tabulate how many of 1000 one-year-olds were still alive at each later age. The fall from one age to the next is the probability of dying in that year, the first estimate of what reliability engineers call the *hazard rate* (:func:`~engineeringkit.reliability.life_table_hazard`). Halley's hazard is high in infancy, lowest around age ten and rises steadily with age: the bathtub curve (:func:`~engineeringkit.reliability.bathtub_hazard`) that describes many machines as well as people. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.reliability import bathtub_hazard, life_table_hazard .. GENERATED FROM PYTHON SOURCE LINES 22-27 Halley's table -------------- Persons living at each age from 1 to 84, as printed in the *Philosophical Transactions* (time unit: years). .. GENERATED FROM PYTHON SOURCE LINES 27-43 .. code-block:: Python # fmt: off alive = [ 1000, 855, 798, 760, 732, 710, 692, 680, 670, 661, 653, 646, 640, 634, 628, 622, 616, 610, 604, 598, 592, 586, 579, 573, 567, 560, 553, 546, 539, 531, 523, 515, 507, 499, 490, 481, 472, 463, 454, 445, 436, 427, 417, 407, 397, 387, 377, 367, 357, 346, 335, 324, 313, 302, 292, 282, 272, 262, 252, 242, 232, 222, 212, 202, 192, 182, 172, 162, 152, 142, 131, 120, 109, 98, 88, 78, 68, 58, 50, 41, 34, 28, 23, 20, ] # fmt: on ages = np.arange(1, 85) hazard = life_table_hazard(ages, alive) young = int(ages[np.argmin(hazard)]) print(f"hazard at age 1: {hazard[0]:.3f}/yr, lowest {hazard.min():.4f}/yr at age {young}, at age 80: {hazard[79]:.3f}/yr") .. rst-class:: sphx-glr-script-out .. code-block:: none hazard at age 1: 0.157/yr, lowest 0.0093/yr at age 12, at age 80: 0.187/yr .. GENERATED FROM PYTHON SOURCE LINES 44-49 A bathtub hazard through the same data -------------------------------------- Infant mortality decaying over a few years, a constant floor and a wear-out term growing as a power of age, fitted by eye. .. GENERATED FROM PYTHON SOURCE LINES 49-63 .. code-block:: Python h = bathtub_hazard(ages + 0.5, early_scale=0.2, early_rate=0.8, random_rate=0.008, wear_scale=2.5e-11, wear_power=5.5) fig, ax = plt.subplots(figsize=(6.5, 3.8)) ax.semilogy(ages[:-1] + 0.5, hazard, "o", ms=3, label="Halley 1693 (Breslau)") ax.semilogy(ages + 0.5, h, label="bathtub model") ax.set(xlabel="age [years]", ylabel="hazard rate [1/year]", title="The human bathtub curve") ax.legend() fig.tight_layout() # The hazard falls through childhood, then rises: a bathtub, not a constant. assert hazard[0] > 5 * hazard.min() and hazard[78] > 5 * hazard.min() assert 5 <= young <= 20 plt.show() .. image-sg:: /api/gallery/reliability/lifetimes/images/sphx_glr_plot_01_halley_life_table_001.png :alt: The human bathtub curve :srcset: /api/gallery/reliability/lifetimes/images/sphx_glr_plot_01_halley_life_table_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.041 seconds) .. _sphx_glr_download_api_gallery_reliability_lifetimes_plot_01_halley_life_table.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/reliability/lifetimes/plot_01_halley_life_table.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_halley_life_table.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_halley_life_table.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_halley_life_table.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_