{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "e51d191c",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "ab0adce0",
            "cell_type": "markdown",
            "source": "Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.\n",
            "metadata": {}
        },
        {
            "id": "0c27fb92",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.special import fdtr\nfdtr(1, 2, 1)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.5773502691896258"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "56d74d66",
            "cell_type": "markdown",
            "source": "Calculate the function at several points by providing a NumPy array for\n`x`.\n",
            "metadata": {}
        },
        {
            "id": "ab2277b0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.array([0.5, 2., 3.])\nfdtr(1, 2, x)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0.4472136 , 0.70710678, 0.77459667])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "070bf5c2",
            "cell_type": "markdown",
            "source": "Plot the function for several parameter sets.\n",
            "metadata": {}
        },
        {
            "id": "b7e4dc94",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\ndfn_parameters = [1, 5, 10, 50]\ndfd_parameters = [1, 1, 2, 3]\nlinestyles = ['solid', 'dashed', 'dotted', 'dashdot']\nparameters_list = list(zip(dfn_parameters, dfd_parameters,\n                           linestyles))\nx = np.linspace(0, 30, 1000)\nfig, ax = plt.subplots()\nfor parameter_set in parameters_list:\n    dfn, dfd, style = parameter_set\n    fdtr_vals = fdtr(dfn, dfd, x)\n    ax.plot(x, fdtr_vals, label=rf\"$d_n={dfn},\\, d_d={dfd}$\",\n            ls=style)\nax.legend()\nax.set_xlabel(\"$x$\")\nax.set_title(\"F distribution cumulative distribution function\")\nplt.show()",
            "outputs": []
        },
        {
            "id": "50940cea",
            "cell_type": "markdown",
            "source": "The F distribution is also available as `scipy.stats.f`. Using `fdtr`\ndirectly can be much faster than calling the ``cdf`` method of\n`scipy.stats.f`, especially for small arrays or individual values.\nTo get the same results one must use the following parametrization:\n``stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)``.\n",
            "metadata": {}
        },
        {
            "id": "c19ff9bf",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats import f\ndfn, dfd = 1, 2\nx = 1\nfdtr_res = fdtr(dfn, dfd, x)  # this will often be faster than below\nf_dist_res = f(dfn, dfd).cdf(x)\nfdtr_res == f_dist_res  # test that results are equal",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}