pastas.stats.tests.runs_test ============================ .. py:function:: pastas.stats.tests.runs_test(series: pandas.Series, cutoff: str = 'median') -> tuple[float, float] Runs test for autocorrelation. :param series: Time series to test for autocorrelation. :type series: pandas.Series :param cutoff: String set to "mean", "median", or a float value to use as the cutoff. :type cutoff: str or float, optional :returns: * **z_stat** (*float*) -- Runs test statistic. * **pval** (*float*) -- p-value for the test statistic, based on a normal distribution. .. rubric:: Notes Wald and Wolfowitz developed [R04c1b8fcc520-wald_1943]_ developed a distribution free test ( i.e., no normal distribution is assumed) to test for autocorrelation. This test is also appropriate for non-equidistant time steps in the residuals time series. The Null-hypothesis is that the residual time series is a random sequence of positive and negative values. The alternative hypothesis is that they are non-random. The test statistic is computed as follows: .. math:: Z = \frac{R-\bar{R}}{\sigma_R} where $R$ is the number of runs, :math:`\bar{R}` the expected number of runs and :math:`\sigma_R` the standard deviation of the number of runs. A run is defined as the number of sequences of exclusively positive and negative values in the time series. **Considerations for this test:** - Test is also applicable to time series with non-equidistant time steps. .. rubric:: References .. [R04c1b8fcc520-wald_1943] Wald, A., & Wolfowitz, J. (1943). An exact test for randomness in the non-parametric case based on serial correlation. The Annals of Mathematical Statistics, 14(4), 378-388. .. rubric:: Examples >>> res = pd.Series(index=pd.date_range(start=0, periods=1000, freq="D"), >>> data=np.random.rand(1000)) >>> stat, pval = ps.stats.runs_test(res) >>> if p > alpha: >>> print("Failed to reject the Null-hypothesis, no significant" >>> "autocorrelation. p =", p.round(2)) >>> else: >>> print("Reject the Null-hypothesis") .. !! processed by numpydoc !!