.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/analytical/statistics/plot_02_horwitz_trumpet.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_analytical_statistics_plot_02_horwitz_trumpet.py: The Horwitz trumpet: interlaboratory precision vs. concentration ================================================================== :func:`~chemistrykit.analytical.horwitz_rsd` gives Horwitz's empirical expected between-laboratory RSD, :math:`2^{1-0.5\log_{10}C}`, which doubles for every 100-fold drop in concentration. Plotted as :math:`\pm\text{RSD}` against concentration it opens like a trumpet. :func:`~chemistrykit.analytical.horrat` scores a method's observed RSD against it. .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.analytical import horrat, horwitz_rsd for label, C in [("pure substance", 1.0), ("1 %", 1e-2), ("1 ppm", 1e-6), ("1 ppb", 1e-9)]: print(f"{label:15s}: predicted RSD_R = {horwitz_rsd(C):5.1f} %") .. rst-class:: sphx-glr-script-out .. code-block:: none pure substance : predicted RSD_R = 2.0 % 1 % : predicted RSD_R = 4.0 % 1 ppm : predicted RSD_R = 16.0 % 1 ppb : predicted RSD_R = 45.3 % .. GENERATED FROM PYTHON SOURCE LINES 23-24 Hypothetical collaborative-study results: (mass fraction, observed RSD %) .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python studies = {"protein in feed": (0.2, 2.1), "pesticide residue": (5e-8, 30.0), "aflatoxin (poor method)": (5e-9, 110.0), "Na in serum": (3e-3, 2.0)} print() for name, (C, rsd) in studies.items(): print(f"{name:24s}: observed {rsd:5.1f} %, Horwitz {horwitz_rsd(C):5.1f} %, HorRat = {horrat(rsd, C):.2f}") .. rst-class:: sphx-glr-script-out .. code-block:: none protein in feed : observed 2.1 %, Horwitz 2.5 %, HorRat = 0.82 pesticide residue : observed 30.0 %, Horwitz 25.1 %, HorRat = 1.19 aflatoxin (poor method) : observed 110.0 %, Horwitz 35.5 %, HorRat = 3.10 Na in serum : observed 2.0 %, Horwitz 4.8 %, HorRat = 0.42 .. GENERATED FROM PYTHON SOURCE LINES 30-44 .. code-block:: Python C = np.logspace(-10, 0, 300) fig, ax = plt.subplots(figsize=(7, 4.5)) ax.plot(C, horwitz_rsd(C), color="black", label=r"$+\mathrm{RSD}_R$") ax.plot(C, -horwitz_rsd(C), color="black", label=r"$-\mathrm{RSD}_R$") ax.fill_between(C, -horwitz_rsd(C), horwitz_rsd(C), color="gray", alpha=0.15) for name, (Cs, rsd) in studies.items(): ax.plot([Cs], [rsd], "o", label=f"{name} (HorRat {horrat(rsd, Cs):.1f})") ax.set_xscale("log") ax.set_xlabel("concentration (mass fraction)") ax.set_ylabel("between-laboratory RSD (%)") ax.set_title("The Horwitz trumpet") ax.legend(fontsize=8) plt.tight_layout() plt.show() .. image-sg:: /api/gallery/analytical/statistics/images/sphx_glr_plot_02_horwitz_trumpet_001.png :alt: The Horwitz trumpet :srcset: /api/gallery/analytical/statistics/images/sphx_glr_plot_02_horwitz_trumpet_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.061 seconds) .. _sphx_glr_download_api_gallery_analytical_statistics_plot_02_horwitz_trumpet.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_horwitz_trumpet.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_horwitz_trumpet.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_horwitz_trumpet.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_