.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/analytical/qtest/plot_01_dixon_q_test.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_qtest_plot_01_dixon_q_test.py: Dixon's Q-test for outlier rejection ======================================== :func:`~chemistrykit.analytical.systems.qtest.dixon_q_test` compares the gap between a suspect value and its nearest neighbor, relative to the full data range, against a tabulated critical value (:data:`~chemistrykit.analytical.systems.qtest.Q_CRITICAL_TABLE`) that depends on sample size and confidence level. .. GENERATED FROM PYTHON SOURCE LINES 13-15 .. code-block:: Python from chemistrykit.analytical.systems.qtest import Q_CRITICAL_TABLE, dixon_q_test .. GENERATED FROM PYTHON SOURCE LINES 16-17 Five replicate titration endpoints (mL), one of them clearly off: .. GENERATED FROM PYTHON SOURCE LINES 17-24 .. code-block:: Python replicates = [24.51, 24.55, 24.48, 24.53, 25.10] for confidence in (0.90, 0.95, 0.99): result = dixon_q_test(replicates, confidence=confidence) verdict = "REJECT" if result.reject else "retain" print(f"confidence={confidence:.0%}: suspect={result.suspect_value}, Q={result.Q_statistic:.4f}, Q_crit={result.Q_critical:.4f} -> {verdict}") .. rst-class:: sphx-glr-script-out .. code-block:: none confidence=90%: suspect=25.1, Q=0.8871, Q_crit=0.6420 -> REJECT confidence=95%: suspect=25.1, Q=0.8871, Q_crit=0.7100 -> REJECT confidence=99%: suspect=25.1, Q=0.8871, Q_crit=0.8210 -> REJECT .. GENERATED FROM PYTHON SOURCE LINES 25-28 The critical value grows with confidence level (harder to reject at higher confidence) and shrinks with sample size (more data makes a single outlier easier to identify): .. GENERATED FROM PYTHON SOURCE LINES 28-32 .. code-block:: Python print("\nQ_crit(n, 95%) for n=3..10:") for n in range(3, 11): print(f" n={n}: {Q_CRITICAL_TABLE[n][0.95]}") .. rst-class:: sphx-glr-script-out .. code-block:: none Q_crit(n, 95%) for n=3..10: n=3: 0.97 n=4: 0.829 n=5: 0.71 n=6: 0.625 n=7: 0.568 n=8: 0.526 n=9: 0.493 n=10: 0.466 .. GENERATED FROM PYTHON SOURCE LINES 33-35 If the suspect value were retained instead (a smaller, more plausible deviation), the Q-test would not reject it even at 90% confidence: .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: Python close_replicates = [24.51, 24.55, 24.48, 24.53, 24.62] result = dixon_q_test(close_replicates, confidence=0.90) print(f"\nCloser data set: Q={result.Q_statistic:.4f}, Q_crit={result.Q_critical:.4f}, reject={result.reject}") .. rst-class:: sphx-glr-script-out .. code-block:: none Closer data set: Q=0.5000, Q_crit=0.6420, reject=False .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 seconds) .. _sphx_glr_download_api_gallery_analytical_qtest_plot_01_dixon_q_test.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_dixon_q_test.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_dixon_q_test.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_dixon_q_test.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_