{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The power is simulated as follows:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Draw many random samples (or sets of samples), each of the size(s)   specified by "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_observations"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", under the alternative specified by   "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For each sample (or set of samples), compute the p-value according to   "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". These p-values are recorded in the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pvalues"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute of   the result object."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Compute the proportion of p-values that are less than the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "significance"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   level. This is the power recorded in the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "power"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute of the   result object."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Suppose that "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "significance"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is an array with shape "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the elements of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "kwargs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "n_observations"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are mutually broadcastable to shape "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "test"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " returns an array of p-values of shape "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Then the result object "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "power"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute will be of shape "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape1 + shape2 + shape3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pvalues"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute will be of shape "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape2 + shape3 + (n_resamples,)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "power",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ✅                   \nPyTorch               ✅                     ✅                   \nJAX                   ⚠️ no JIT             ⚠️ no JIT           \nDask                  ⚠️ computes graph     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "res",
              "annotation": "PowerResult",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object with attributes:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "power"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "power"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "pvalues"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "pvalues"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Simulate the power of a hypothesis test under an alternative hypothesis."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "test",
              "annotation": "callable",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Hypothesis test for which the power is to be simulated. "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must be a callable that accepts a sample (e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "test(sample)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ") or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "len(rvs)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " separate samples (e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "test(samples1, sample2)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " contains two callables and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_observations"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " contains two values) and returns the p-value of the test. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "vectorized"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is set to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must also accept a keyword argument "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and be vectorized to perform the test along the provided "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of the samples. Any callable from "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.stats"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with an "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " argument that returns an object with a "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "pvalue",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute is also acceptable."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rvs",
              "annotation": "callable or tuple of callables",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A callable or sequence of callables that generate(s) random variates under the alternative hypothesis. Each element of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must accept keyword argument "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "size"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rvs(size=(m, n))"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ") and return an N-d array of that shape. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a sequence, the number of callables in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must match the number of elements of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_observations"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", i.e. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "len(rvs) == len(n_observations)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a single callable, "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_observations"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is treated as a single element."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n_observations",
              "annotation": "tuple of ints or tuple of integer arrays",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If a sequence of ints, each is the sizes of a sample to be passed to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If a sequence of integer arrays, the power is simulated for each set of corresponding sample sizes. See Examples."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "significance",
              "annotation": "float or array_like of floats, default: 0.01",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The threshold for significance; i.e., the p-value below which the hypothesis test results will be considered as evidence against the null hypothesis. Equivalently, the acceptable rate of Type I error under the null hypothesis. If an array, the power is simulated for each significance threshold."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "kwargs",
              "annotation": "dict, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Keyword arguments to be passed to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and/or "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " callables. Introspection is used to determine which keyword arguments may be passed to each callable. The value corresponding with each keyword must be an array. Arrays must be broadcastable with one another and with each array in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_observations"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". The power is simulated for each set of corresponding sample sizes and arguments. See Examples."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "vectorized",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "vectorized"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is set to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "False"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will not be passed keyword argument "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and is expected to perform the test only for 1D samples. If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will be passed keyword argument "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and is expected to perform the test along "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "axis",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " when passed N-D sample arrays. If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (default), "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "vectorized"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will be set "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a parameter of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Use of a vectorized test typically reduces computation time."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n_resamples",
              "annotation": "int, default: 10000",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of samples drawn from each of the callables of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Equivalently, the number tests performed under the alternative hypothesis to approximate the power."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "batch",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The number of samples to process in each call to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "test"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Memory usage is proportional to the product of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "batch"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and the largest sample size. Default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", in which case "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "batch"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " equals "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "n_resamples"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/stats/_resampling.py",
  "item_line": 1128,
  "item_type": "function",
  "aliases": [
    "scipy.stats.power"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Suppose we wish to simulate the power of the independent sample t-test\nunder the following conditions:\n\n- The first sample has 10 observations drawn from a normal distribution\n  with mean 0.\n- The second sample has 12 observations drawn from a normal distribution\n  with mean 1.0.\n- The threshold on p-values for significance is 0.05.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng(2549598345528)\ntest = stats.ttest_ind\nn_observations = (10, 12)\nrvs1 = rng.normal\nrvs2 = lambda size: rng.normal(loc=1, size=size)\nrvs = (rvs1, rvs2)\nres = stats.power(test, rvs, n_observations, significance=0.05)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "res.power\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWith samples of size 10 and 12, respectively, the power of the t-test\nwith a significance threshold of 0.05 is approximately 60% under the chosen\nalternative. We can investigate the effect of sample size on the power\nby passing sample size arrays.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nnobs_x = np.arange(5, 21)\nnobs_y = nobs_x\nn_observations = (nobs_x, nobs_y)\nres = stats.power(test, rvs, n_observations, significance=0.05)\nax = plt.subplot()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(nobs_x, res.power)\nax.set_xlabel('Sample Size')\nax.set_ylabel('Simulated Power')\nax.set_title('Simulated Power of `ttest_ind` with Equal Sample Sizes')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-5e3d2efa8d475e1b.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAlternatively, we can investigate the impact that effect size has on the power.\nIn this case, the effect size is the location of the distribution underlying\nthe second sample.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "n_observations = (10, 12)\nloc = np.linspace(0, 1, 20)\nrvs2 = lambda size, loc: rng.normal(loc=loc, size=size)\nrvs = (rvs1, rvs2)\nres = stats.power(test, rvs, n_observations, significance=0.05,\n                  kwargs={'loc': loc})\nax = plt.subplot()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(loc, res.power)\nax.set_xlabel('Effect Size')\nax.set_ylabel('Simulated Power')\nax.set_title('Simulated Power of `ttest_ind`, Varying Effect Size')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-5f1da2f52efc7353.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWe can also use `power` to estimate the Type I error rate (also referred to by the\nambiguous term \"size\") of a test and assess whether it matches the nominal level.\nFor example, the null hypothesis of `jarque_bera` is that the sample was drawn from\na distribution with the same skewness and kurtosis as the normal distribution. To\nestimate the Type I error rate, we can consider the null hypothesis to be a true\n*alternative* hypothesis and calculate the power.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "test = stats.jarque_bera\nn_observations = 10\nrvs = rng.normal\nsignificance = np.linspace(0.0001, 0.1, 1000)\nres = stats.power(test, rvs, n_observations, significance=significance)\nsize = res.power\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAs shown below, the Type I error rate of the test is far below the nominal level\nfor such a small sample, as mentioned in its documentation.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax = plt.subplot()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(significance, size)\nax.plot([0, 0.1], [0, 0.1], '--')\nax.set_xlabel('nominal significance level')\nax.set_ylabel('estimated test size (Type I error rate)')\nax.set_title('Estimated test size vs nominal significance level')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.set_aspect('equal', 'box')\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.legend(('`ttest_1samp`', 'ideal test'))\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-19537af9278498fc.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAs one might expect from such a conservative test, the power is quite low with\nrespect to some alternatives. For example, the power of the test under the\nalternative that the sample was drawn from the Laplace distribution may not\nbe much greater than the Type I error rate.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = rng.laplace\nsignificance = np.linspace(0.0001, 0.1, 1000)\nres = stats.power(test, rvs, n_observations, significance=0.05)\nprint(res.power)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThis is not a mistake in SciPy's implementation; it is simply due to the fact\nthat the null distribution of the test statistic is derived under the assumption\nthat the sample size is large (i.e. approaches infinity), and this asymptotic\napproximation is not accurate for small samples. In such cases, resampling\nand Monte Carlo methods (e.g. `permutation_test`, `goodness_of_fit`,\n`monte_carlo_test`) may be more appropriate."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "test",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rvs",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n_observations",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "significance",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "0.01"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "vectorized",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n_resamples",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "10000"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "batch",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "kwargs",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "power"
  },
  "references": null,
  "qa": "scipy.stats._resampling:power",
  "arbitrary": [],
  "local_refs": [
    "batch",
    "kwargs",
    "n_observations",
    "n_resamples",
    "res",
    "rvs",
    "significance",
    "test",
    "vectorized"
  ]
}