def kpss(x, regression='c', lags=None, store=False):
    "\n    Kwiatkowski-Phillips-Schmidt-Shin test for stationarity.\n\n    Computes the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test for the null\n    hypothesis that x is level or trend stationary.\n\n    Parameters\n    ----------\n    x : array_like, 1d\n        Data series\n    regression : str{'c', 'ct'}\n        Indicates the null hypothesis for the KPSS test\n        * 'c' : The data is stationary around a constant (default)\n        * 'ct' : The data is stationary around a trend\n    lags : int\n        Indicates the number of lags to be used. If None (default),\n        lags is set to int(12 * (n / 100)**(1 / 4)), as outlined in\n        Schwert (1989).\n    store : bool\n        If True, then a result instance is returned additionally to\n        the KPSS statistic (default is False).\n\n    Returns\n    -------\n    kpss_stat : float\n        The KPSS test statistic\n    p_value : float\n        The p-value of the test. The p-value is interpolated from\n        Table 1 in Kwiatkowski et al. (1992), and a boundary point\n        is returned if the test statistic is outside the table of\n        critical values, that is, if the p-value is outside the\n        interval (0.01, 0.1).\n    lags : int\n        The truncation lag parameter\n    crit : dict\n        The critical values at 10%, 5%, 2.5% and 1%. Based on\n        Kwiatkowski et al. (1992).\n    resstore : (optional) instance of ResultStore\n        An instance of a dummy class with results attached as attributes\n\n    Notes\n    -----\n    To estimate sigma^2 the Newey-West estimator is used. If lags is None,\n    the truncation lag parameter is set to int(12 * (n / 100) ** (1 / 4)),\n    as outlined in Schwert (1989). The p-values are interpolated from\n    Table 1 of Kwiatkowski et al. (1992). If the computed statistic is\n    outside the table of critical values, then a warning message is\n    generated.\n\n    Missing values are not handled.\n\n    References\n    ----------\n    D. Kwiatkowski, P. C. B. Phillips, P. Schmidt, and Y. Shin (1992): Testing\n    the Null Hypothesis of Stationarity against the Alternative of a Unit Root.\n    `Journal of Econometrics` 54, 159-178.\n    "
    from warnings import warn
    nobs = len(x)
    x = np.asarray(x)
    hypo = regression.lower()
    if (nobs != x.size):
        raise ValueError('x of shape {0} not understood'.format(x.shape))
    if (hypo == 'ct'):
        resids = OLS(x, add_constant(np.arange(1, (nobs + 1)))).fit().resid
        crit = [0.119, 0.146, 0.176, 0.216]
    elif (hypo == 'c'):
        resids = (x - x.mean())
        crit = [0.347, 0.463, 0.574, 0.739]
    else:
        raise ValueError("hypothesis '{0}' not understood".format(hypo))
    if (lags is None):
        lags = int(np.ceil((12.0 * np.power((nobs / 100.0), (1 / 4.0)))))
    pvals = [0.1, 0.05, 0.025, 0.01]
    eta = (sum((resids.cumsum() ** 2)) / (nobs ** 2))
    s_hat = _sigma_est_kpss(resids, nobs, lags)
    kpss_stat = (eta / s_hat)
    p_value = np.interp(kpss_stat, crit, pvals)
    if (p_value == pvals[(- 1)]):
        warn('p-value is smaller than the indicated p-value', InterpolationWarning)
    elif (p_value == pvals[0]):
        warn('p-value is greater than the indicated p-value', InterpolationWarning)
    crit_dict = {'10%': crit[0], '5%': crit[1], '2.5%': crit[2], '1%': crit[3]}
    if store:
        rstore = ResultsStore()
        rstore.lags = lags
        rstore.nobs = nobs
        stationary_type = ('level' if (hypo == 'c') else 'trend')
        rstore.H0 = 'The series is {0} stationary'.format(stationary_type)
        rstore.HA = 'The series is not {0} stationary'.format(stationary_type)
        return (kpss_stat, p_value, crit_dict, rstore)
    else:
        return (kpss_stat, p_value, lags, crit_dict)
Kwiatkowski-Phillips-Schmidt-Shin test for stationarity.

Computes the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test for the null
hypothesis that x is level or trend stationary.

Parameters
----------
x : array_like, 1d
    Data series
regression : str{'c', 'ct'}
    Indicates the null hypothesis for the KPSS test
    * 'c' : The data is stationary around a constant (default)
    * 'ct' : The data is stationary around a trend
lags : int
    Indicates the number of lags to be used. If None (default),
    lags is set to int(12 * (n / 100)**(1 / 4)), as outlined in
    Schwert (1989).
store : bool
    If True, then a result instance is returned additionally to
    the KPSS statistic (default is False).

Returns
-------
kpss_stat : float
    The KPSS test statistic
p_value : float
    The p-value of the test. The p-value is interpolated from
    Table 1 in Kwiatkowski et al. (1992), and a boundary point
    is returned if the test statistic is outside the table of
    critical values, that is, if the p-value is outside the
    interval (0.01, 0.1).
lags : int
    The truncation lag parameter
crit : dict
    The critical values at 10%, 5%, 2.5% and 1%. Based on
    Kwiatkowski et al. (1992).
resstore : (optional) instance of ResultStore
    An instance of a dummy class with results attached as attributes

Notes
-----
To estimate sigma^2 the Newey-West estimator is used. If lags is None,
the truncation lag parameter is set to int(12 * (n / 100) ** (1 / 4)),
as outlined in Schwert (1989). The p-values are interpolated from
Table 1 of Kwiatkowski et al. (1992). If the computed statistic is
outside the table of critical values, then a warning message is
generated.

Missing values are not handled.

References
----------
D. Kwiatkowski, P. C. B. Phillips, P. Schmidt, and Y. Shin (1992): Testing
the Null Hypothesis of Stationarity against the Alternative of a Unit Root.
`Journal of Econometrics` 54, 159-178.
def kpss(x, regression='c', lags=None, store=False):
    "\n    Kwiatkowski-Phillips-Schmidt-Shin test for stationarity.\n\n    Computes the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test for the null\n    hypothesis that x is level or trend stationary.\n\n    Parameters\n    ----------\n    x : array_like, 1d\n        Data series\n    regression : str{'c', 'ct'}\n        Indicates the null hypothesis for the KPSS test\n        * 'c' : The data is stationary around a constant (default)\n        * 'ct' : The data is stationary around a trend\n    lags : int\n        Indicates the number of lags to be used. If None (default),\n        lags is set to int(12 * (n / 100)**(1 / 4)), as outlined in\n        Schwert (1989).\n    store : bool\n        If True, then a result instance is returned additionally to\n        the KPSS statistic (default is False).\n\n    Returns\n    -------\n    kpss_stat : float\n        The KPSS test statistic\n    p_value : float\n        The p-value of the test. The p-value is interpolated from\n        Table 1 in Kwiatkowski et al. (1992), and a boundary point\n        is returned if the test statistic is outside the table of\n        critical values, that is, if the p-value is outside the\n        interval (0.01, 0.1).\n    lags : int\n        The truncation lag parameter\n    crit : dict\n        The critical values at 10%, 5%, 2.5% and 1%. Based on\n        Kwiatkowski et al. (1992).\n    resstore : (optional) instance of ResultStore\n        An instance of a dummy class with results attached as attributes\n\n    Notes\n    -----\n    To estimate sigma^2 the Newey-West estimator is used. If lags is None,\n    the truncation lag parameter is set to int(12 * (n / 100) ** (1 / 4)),\n    as outlined in Schwert (1989). The p-values are interpolated from\n    Table 1 of Kwiatkowski et al. (1992). If the computed statistic is\n    outside the table of critical values, then a warning message is\n    generated.\n\n    Missing values are not handled.\n\n    References\n    ----------\n    D. Kwiatkowski, P. C. B. Phillips, P. Schmidt, and Y. Shin (1992): Testing\n    the Null Hypothesis of Stationarity against the Alternative of a Unit Root.\n    `Journal of Econometrics` 54, 159-178.\n    "
    from warnings import warn
    nobs = len(x)
    x = np.asarray(x)
    hypo = regression.lower()
    if (nobs != x.size):
        raise ValueError('x of shape {0} not understood'.format(x.shape))
    if (hypo == 'ct'):
        resids = OLS(x, add_constant(np.arange(1, (nobs + 1)))).fit().resid
        crit = [0.119, 0.146, 0.176, 0.216]
    elif (hypo == 'c'):
        resids = (x - x.mean())
        crit = [0.347, 0.463, 0.574, 0.739]
    else:
        raise ValueError("hypothesis '{0}' not understood".format(hypo))
    if (lags is None):
        lags = int(np.ceil((12.0 * np.power((nobs / 100.0), (1 / 4.0)))))
    pvals = [0.1, 0.05, 0.025, 0.01]
    eta = (sum((resids.cumsum() ** 2)) / (nobs ** 2))
    s_hat = _sigma_est_kpss(resids, nobs, lags)
    kpss_stat = (eta / s_hat)
    p_value = np.interp(kpss_stat, crit, pvals)
    if (p_value == pvals[(- 1)]):
        warn('p-value is smaller than the indicated p-value', InterpolationWarning)
    elif (p_value == pvals[0]):
        warn('p-value is greater than the indicated p-value', InterpolationWarning)
    crit_dict = {'10%': crit[0], '5%': crit[1], '2.5%': crit[2], '1%': crit[3]}
    if store:
        rstore = ResultsStore()
        rstore.lags = lags
        rstore.nobs = nobs
        stationary_type = ('level' if (hypo == 'c') else 'trend')
        rstore.H0 = 'The series is {0} stationary'.format(stationary_type)
        rstore.HA = 'The series is not {0} stationary'.format(stationary_type)
        return (kpss_stat, p_value, crit_dict, rstore)
    else:
        return (kpss_stat, p_value, lags, crit_dict)