{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This test and its method for computing confidence intervals are non-parametric. They are valid if and only if the observations are i.i.d."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The implementation of the test follows Conover "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Two test statistics are considered."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "T1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": The number of observations in "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " less than or equal to "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "q"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "T1 = (x <= q).sum()"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "T2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": The number of observations in "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " strictly less than "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "q"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "T2 = (x < q).sum()"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The use of two test statistics is necessary to handle the possibility that "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " was generated from a discrete or mixed distribution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The null hypothesis for the test is:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "H0: The "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "p^{\\mathrm{th}}"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " population quantile is "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "q"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "and the null distribution for each test statistic is "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mathrm{binom}\\left(n, p\\right)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". When "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "alternative='less'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the alternative hypothesis is:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "H1: The "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "p^{\\mathrm{th}}"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " population quantile is less than "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "q"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "and the p-value is the probability that the binomial random variable"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Y \\sim \\mathrm{binom}\\left(n, p\\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "is greater than or equal to the observed value "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "T2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "alternative='greater'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the alternative hypothesis is:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "H1: The "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "p^{\\mathrm{th}}"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " population quantile is greater than "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "q"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "and the p-value is the probability that the binomial random variable Y is less than or equal to the observed value "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "T1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "alternative='two-sided'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the alternative hypothesis is"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "H1: "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "q"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " is not the "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "p^{\\mathrm{th}}"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " population quantile."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "and the p-value is twice the smaller of the p-values for the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'less'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'greater'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " cases. Both of these p-values can exceed 0.5 for the same data, so the value is clipped into the interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[0, 1]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The approach for confidence intervals is attributed to Thompson "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and later proven to be applicable to any set of i.i.d. samples "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The computation is based on the observation that the probability of a quantile "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "q"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to be larger than any observations "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_m (1\\leq m \\leq N)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be computed as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\mathbb{P}(x_m \\leq q) = 1 - \\sum_{k=0}^{m-1} \\binom{N}{k}\nq^k(1-q)^{N-k}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default, confidence intervals are computed for a 95% confidence level. A common interpretation of a 95% confidence intervals is that if i.i.d. samples are drawn repeatedly from the same population and confidence intervals are formed each time, the confidence interval will contain the true value of the specified quantile in approximately 95% of trials."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A similar function is available in the QuantileNPCI R package "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The foundation is the same, but it computes the confidence interval bounds by doing interpolations between the sample values, whereas this function uses only sample values as bounds. Thus, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "quantile_test.confidence_interval"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " returns more conservative intervals (i.e., larger)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The same computation of confidence intervals for quantiles is included in the confintr package "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Two-sided confidence intervals are not guaranteed to be optimal; i.e., there may exist a tighter interval that may contain the quantile of interest with probability larger than the confidence level. Without further assumption on the samples (e.g., the nature of the underlying distribution), the one-sided intervals are optimally tight."
            }
          ]
        },
        {
          "__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": "CrossRef",
              "__tag": 4002,
              "value": "quantile_test",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.stats._stats_py:quantile_test"
              },
              "kind": "module"
            },
            {
              "__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                   ⛔                     ⛔                   \nDask                  ⛔                     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": "result",
              "annotation": "QuantileTestResult",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object with the following attributes:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "statistic"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "statistic"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "statistic_type"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "statistic_type"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "pvalue"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "pvalue"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The object also has the following method:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "confidence_interval(confidence_level=0.95)"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "Computes a confidence interval around the the     population quantile associated with the probability "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "p"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": ". The     confidence interval is returned in a "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "namedtuple"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " with     fields "
                            },
                            {
                              "__type": "InlineRole",
                              "__tag": 4003,
                              "value": "low",
                              "domain": null,
                              "role": null,
                              "inventory": null
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " and "
                            },
                            {
                              "__type": "InlineRole",
                              "__tag": 4003,
                              "value": "high",
                              "domain": null,
                              "role": null,
                              "inventory": null
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": ".  Values are "
                            },
                            {
                              "__type": "InlineRole",
                              "__tag": 4003,
                              "value": "nan",
                              "domain": null,
                              "role": null,
                              "inventory": null
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " when there are     not enough observations to compute the confidence interval at     the desired confidence."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Perform a quantile test and compute a confidence interval of the quantile."
            }
          ]
        }
      ],
      "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": "x",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A one-dimensional sample."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "q",
              "annotation": "float, default: 0",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The hypothesized value of the quantile."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "p",
              "annotation": "float, default: 0.5",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The probability associated with the quantile; i.e. the proportion of the population less than "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "q"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Must be strictly between 0 and 1."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "alternative",
              "annotation": "{'two-sided', 'less', 'greater'}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Defines the alternative hypothesis. The following options are available (default is 'two-sided'):"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'two-sided': the quantile associated with the probability "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "p"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "   is not "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "q"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'less': the quantile associated with the probability "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "p"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is less   than "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "q"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'greater': the quantile associated with the probability "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "p"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is   greater than "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "q"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This function tests the null hypothesis that "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "q"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the value of the quantile associated with probability "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of the population underlying sample "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For example, with default parameters, it tests that the median of the population underlying "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is zero. The function returns an object including the test statistic, a p-value, and a method for computing the confidence interval around the quantile."
            }
          ]
        }
      ],
      "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/_stats_py.py",
  "item_line": 9048,
  "item_type": "function",
  "aliases": [
    "scipy.stats.quantile_test"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Suppose we wish to test the null hypothesis that the median of a population\nis equal to 0.5. We choose a confidence level of 99%; that is, we will\nreject the null hypothesis in favor of the alternative if the p-value is\nless than 0.01.\n\nWhen testing random variates from the standard uniform distribution, which\nhas a median of 0.5, we expect the data to be consistent with the null\nhypothesis most of the time.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng(6981396440634228121)\nrvs = stats.uniform.rvs(size=100, random_state=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "stats.quantile_test(rvs, q=0.5, p=0.5)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAs expected, the p-value is not below our threshold of 0.01, so\nwe cannot reject the null hypothesis.\n\nWhen testing data from the standard *normal* distribution, which has a\nmedian of 0, we would expect the null hypothesis to be rejected.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = stats.norm.rvs(size=100, random_state=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "stats.quantile_test(rvs, q=0.5, p=0.5)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIndeed, the p-value is lower than our threshold of 0.01, so we reject the\nnull hypothesis in favor of the default \"two-sided\" alternative: the median\nof the population is *not* equal to 0.5.\n\nHowever, suppose we were to test the null hypothesis against the\none-sided alternative that the median of the population is *greater* than\n0.5. Since the median of the standard normal is less than 0.5, we would not\nexpect the null hypothesis to be rejected.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "stats.quantile_test(rvs, q=0.5, p=0.5, alternative='greater')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nUnsurprisingly, with a p-value greater than our threshold, we would not\nreject the null hypothesis in favor of the chosen alternative.\n\nThe quantile test can be used for any quantile, not only the median. For\nexample, we can test whether the third quartile of the distribution\nunderlying the sample is greater than 0.6.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = stats.uniform.rvs(size=100, random_state=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "stats.quantile_test(rvs, q=0.6, p=0.75, alternative='greater')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe p-value is lower than the threshold. We reject the null hypothesis in\nfavor of the alternative: the third quartile of the distribution underlying\nour sample is greater than 0.6.\n\n`quantile_test` can also compute confidence intervals for any quantile.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = stats.norm.rvs(size=100, random_state=rng)\nres = stats.quantile_test(rvs, q=0.6, p=0.75)\nci = res.confidence_interval(confidence_level=0.95)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ci\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWhen testing a one-sided alternative, the confidence interval contains\nall observations such that if passed as `q`, the p-value of the\ntest would be greater than 0.05, and therefore the null hypothesis\nwould not be rejected. For example:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs.sort()\nq, p, alpha = 0.6, 0.75, 0.95\nres = stats.quantile_test(rvs, q=q, p=p, alternative='less')\nci = res.confidence_interval(confidence_level=alpha)\nfor x in rvs[rvs <= ci.high]:\n    res = stats.quantile_test(rvs, q=x, p=p, alternative='less')\n    assert res.pvalue > 1-alpha\nfor x in rvs[rvs > ci.high]:\n    res = stats.quantile_test(rvs, q=x, p=p, alternative='less')\n    assert res.pvalue < 1-alpha\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAlso, if a 95% confidence interval is repeatedly generated for random\nsamples, the confidence interval will contain the true quantile value in\napproximately 95% of replications.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "dist = stats.rayleigh() # our \"unknown\" distribution\np = 0.2\ntrue_stat = dist.ppf(p) # the true value of the statistic\nn_trials = 1000\nquantile_ci_contains_true_stat = 0\nfor i in range(n_trials):\n    data = dist.rvs(size=100, random_state=rng)\n    res = stats.quantile_test(data, p=p)\n    ci = res.confidence_interval(0.95)\n    if ci[0] < true_stat < ci[1]:\n        quantile_ci_contains_true_stat += 1\nquantile_ci_contains_true_stat >= 950\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThis works with any distribution and any quantile, as long as the samples\nare i.i.d."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "q",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "p",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "0.5"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "alternative",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "two-sided"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "quantile_test"
  },
  "references": [
    ".. [1] W. J. Conover. Practical Nonparametric Statistics, 3rd Ed. 1999.",
    ".. [2] W. R. Thompson, \"On Confidence Ranges for the Median and Other",
    "   Expectation Distributions for Populations of Unknown Distribution",
    "   Form,\" The Annals of Mathematical Statistics, vol. 7, no. 3,",
    "   pp. 122-128, 1936, Accessed: Sep. 18, 2019. [Online]. Available:",
    "   https://www.jstor.org/stable/2957563.",
    ".. [3] H. A. David and H. N. Nagaraja, \"Order Statistics in Nonparametric",
    "   Inference\" in Order Statistics, John Wiley & Sons, Ltd, 2005, pp.",
    "   159-170. Available:",
    "   https://onlinelibrary.wiley.com/doi/10.1002/0471722162.ch7.",
    ".. [4] N. Hutson, A. Hutson, L. Yan, \"QuantileNPCI: Nonparametric",
    "   Confidence Intervals for Quantiles,\" R package,",
    "   https://cran.r-project.org/package=QuantileNPCI",
    ".. [5] M. Mayer, \"confintr: Confidence Intervals,\" R package,",
    "   https://cran.r-project.org/package=confintr"
  ],
  "qa": "scipy.stats._stats_py:quantile_test",
  "arbitrary": [],
  "local_refs": [
    "alternative",
    "p",
    "q",
    "result",
    "x"
  ]
}