{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The slopes "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "d_{ijk}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " within season "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "d_{ijk} = \\frac{x_{ij} - x_{ik}}\n                    {j - k}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for pairs of distinct integer indices "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "j, k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Element "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of the returned "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "intra_slope",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " array is the median of the "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "d_{ijk}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " over all "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "j < k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "; this is the Theil-Sen slope estimator of season "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The returned "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "inter_slope",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " value, better known as the seasonal Kendall slope estimator, is the median of the "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "d_{ijk}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " over all "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i, j, k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "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": "``SenSeasonalSlopesResult`` instance",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The return value is 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": "intra_slope"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "intra_slope"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "inter_slope"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "inter_slope"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Computes seasonal Theil-Sen and Kendall slope estimators."
            }
          ]
        }
      ],
      "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": "2D array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Each column of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " contains measurements of the dependent variable within a season. The independent variable (usually time) of each season is assumed to be "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.arange(x.shape[0])"
                    },
                    {
                      "__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": "The seasonal generalization of Sen's slope computes the slopes between all pairs of values within a \"season\" (column) of a 2D array. It returns an array containing the median of these \"within-season\" slopes for each season (the Theil-Sen slope estimator of each season), and it returns the median of the within-season slopes across all seasons (the seasonal Kendall slope estimator)."
            }
          ]
        }
      ],
      "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/_mstats_basic.py",
  "item_line": 1320,
  "item_type": "function",
  "aliases": [
    "scipy.stats._mstats_basic.sen_seasonal_slopes"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Suppose we have 100 observations of a dependent variable for each of four\nseasons:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nrng = np.random.default_rng()\nx = rng.random(size=(100, 4))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWe compute the seasonal slopes as:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy import stats\nintra_slope, inter_slope = stats.mstats.sen_seasonal_slopes(x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIf we define a function to compute all slopes between observations within\na season:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def dijk(yi):\n    n = len(yi)\n    x = np.arange(n)\n    dy = yi - yi[:, np.newaxis]\n    dx = x - x[:, np.newaxis]\n    # we only want unique pairs of distinct indices\n    mask = np.triu(np.ones((n, n), dtype=bool), k=1)\n    return dy[mask]/dx[mask]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nthen element ``i`` of ``intra_slope`` is the median of ``dijk[x[:, i]]``:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "i = 2\nnp.allclose(np.median(dijk(x[:, i])), intra_slope[i])\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nand ``inter_slope`` is the median of the values returned by ``dijk`` for\nall seasons:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "all_slopes = np.concatenate([dijk(x[:, i]) for i in range(x.shape[1])])\nnp.allclose(np.median(all_slopes), inter_slope)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nBecause the data are randomly generated, we would expect the median slopes\nto be nearly zero both within and across all seasons, and indeed they are:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "intra_slope.data\ninter_slope\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "scipy.stats.theilslopes",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.stats._stats_mstats_common:theilslopes"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "non-seasonal slopes for non-masked arrays"
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "theilslopes",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "theilslopes"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "the analogous function for non-seasonal data"
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "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
        }
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "sen_seasonal_slopes"
  },
  "references": [
    ".. [1] Hirsch, Robert M., James R. Slack, and Richard A. Smith.",
    "       \"Techniques of trend analysis for monthly water quality data.\"",
    "       *Water Resources Research* 18.1 (1982): 107-121."
  ],
  "qa": "scipy.stats._mstats_basic:sen_seasonal_slopes",
  "arbitrary": [],
  "local_refs": [
    "result",
    "x"
  ]
}