.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_models.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_auto_examples_plot_models.py: Model estimates and diagnostics =============================== Fit a model once, then read it from several angles: a coefficient forest, the predicted effect of a predictor, an estimation plot of group differences, and a panel of regression diagnostics. .. GENERATED FROM PYTHON SOURCE LINES 9-18 .. code-block:: Python import statsmodels.formula.api as smf import depictr as dp cy = dp.crop_yield() # Q() quotes "yield" because it is a Python keyword. model = smf.ols('Q("yield") ~ fertiliser + rainfall + soil_ph + treatment', cy).fit() .. GENERATED FROM PYTHON SOURCE LINES 19-20 A dot-and-whisker forest of the coefficients. .. GENERATED FROM PYTHON SOURCE LINES 20-23 .. code-block:: Python p = dp.coefficient_plot(model, title="Drivers of crop yield") p .. image-sg:: /auto_examples/images/sphx_glr_plot_models_001.png :alt: plot models :srcset: /auto_examples/images/sphx_glr_plot_models_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-25 The predicted response as one predictor varies, with a confidence band. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python p = dp.effects_plot(model, "fertiliser") p .. image-sg:: /auto_examples/images/sphx_glr_plot_models_002.png :alt: plot models :srcset: /auto_examples/images/sphx_glr_plot_models_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-30 A two-panel Gardner-Altman estimation plot of the group difference. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python p = dp.estimation_plot(cy, "yield", "treatment", two_panel=True, seed=1) p .. image-sg:: /auto_examples/images/sphx_glr_plot_models_003.png :alt: plot models :srcset: /auto_examples/images/sphx_glr_plot_models_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 The four-panel residual-diagnostic dashboard. .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python p = dp.residual_diagnostics_plot(model) p .. image-sg:: /auto_examples/images/sphx_glr_plot_models_004.png :alt: plot models :srcset: /auto_examples/images/sphx_glr_plot_models_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.080 seconds) .. _sphx_glr_download_auto_examples_plot_models.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_models.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_models.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_models.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_