def adfuller(x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False):
    '\n    Augmented Dickey-Fuller unit root test\n\n    The Augmented Dickey-Fuller test can be used to test for a unit root in a\n    univariate process in the presence of serial correlation.\n\n    Parameters\n    ----------\n    x : array_like, 1d\n        data series\n    maxlag : int\n        Maximum lag which is included in test, default 12*(nobs/100)^{1/4}\n    regression : {\'c\',\'ct\',\'ctt\',\'nc\'}\n        Constant and trend order to include in regression\n\n        * \'c\' : constant only (default)\n        * \'ct\' : constant and trend\n        * \'ctt\' : constant, and linear and quadratic trend\n        * \'nc\' : no constant, no trend\n    autolag : {\'AIC\', \'BIC\', \'t-stat\', None}\n        * if None, then maxlag lags are used\n        * if \'AIC\' (default) or \'BIC\', then the number of lags is chosen\n          to minimize the corresponding information criterion\n        * \'t-stat\' based choice of maxlag.  Starts with maxlag and drops a\n          lag until the t-statistic on the last lag length is significant\n          using a 5%-sized test\n    store : bool\n        If True, then a result instance is returned additionally to\n        the adf statistic. Default is False\n    regresults : bool, optional\n        If True, the full regression results are returned. Default is False\n\n    Returns\n    -------\n    adf : float\n        Test statistic\n    pvalue : float\n        MacKinnon\'s approximate p-value based on MacKinnon (1994, 2010)\n    usedlag : int\n        Number of lags used\n    nobs : int\n        Number of observations used for the ADF regression and calculation of\n        the critical values\n    critical values : dict\n        Critical values for the test statistic at the 1 %, 5 %, and 10 %\n        levels. Based on MacKinnon (2010)\n    icbest : float\n        The maximized information criterion if autolag is not None.\n    resstore : ResultStore, optional\n        A dummy class with results attached as attributes\n\n    Notes\n    -----\n    The null hypothesis of the Augmented Dickey-Fuller is that there is a unit\n    root, with the alternative that there is no unit root. If the pvalue is\n    above a critical size, then we cannot reject that there is a unit root.\n\n    The p-values are obtained through regression surface approximation from\n    MacKinnon 1994, but using the updated 2010 tables. If the p-value is close\n    to significant, then the critical values should be used to judge whether\n    to reject the null.\n\n    The autolag option and maxlag for it are described in Greene.\n\n    Examples\n    --------\n    See example notebook\n\n    References\n    ----------\n    .. [*] W. Green.  "Econometric Analysis," 5th ed., Pearson, 2003.\n\n    .. [*] Hamilton, J.D.  "Time Series Analysis".  Princeton, 1994.\n\n    .. [*] MacKinnon, J.G. 1994.  "Approximate asymptotic distribution functions for\n        unit-root and cointegration tests.  `Journal of Business and Economic\n        Statistics` 12, 167-76.\n\n    .. [*] MacKinnon, J.G. 2010. "Critical Values for Cointegration Tests."  Queen\'s\n        University, Dept of Economics, Working Papers.  Available at\n        http://ideas.repec.org/p/qed/wpaper/1227.html\n    '
    if regresults:
        store = True
    trenddict = {None: 'nc', 0: 'c', 1: 'ct', 2: 'ctt'}
    if ((regression is None) or isinstance(regression, (int, long))):
        regression = trenddict[regression]
    regression = regression.lower()
    if (regression not in ['c', 'nc', 'ct', 'ctt']):
        raise (ValueError('regression option %s not understood') % regression)
    x = np.asarray(x)
    nobs = x.shape[0]
    if (maxlag is None):
        maxlag = int(np.ceil((12.0 * np.power((nobs / 100.0), (1 / 4.0)))))
    xdiff = np.diff(x)
    xdall = lagmat(xdiff[:, None], maxlag, trim='both', original='in')
    nobs = xdall.shape[0]
    xdall[:, 0] = x[((- nobs) - 1):(- 1)]
    xdshort = xdiff[(- nobs):]
    if store:
        resstore = ResultsStore()
    if autolag:
        if (regression != 'nc'):
            fullRHS = add_trend(xdall, regression, prepend=True)
        else:
            fullRHS = xdall
        startlag = ((fullRHS.shape[1] - xdall.shape[1]) + 1)
        if (not regresults):
            (icbest, bestlag) = _autolag(OLS, xdshort, fullRHS, startlag, maxlag, autolag)
        else:
            (icbest, bestlag, alres) = _autolag(OLS, xdshort, fullRHS, startlag, maxlag, autolag, regresults=regresults)
            resstore.autolag_results = alres
        bestlag -= startlag
        xdall = lagmat(xdiff[:, None], bestlag, trim='both', original='in')
        nobs = xdall.shape[0]
        xdall[:, 0] = x[((- nobs) - 1):(- 1)]
        xdshort = xdiff[(- nobs):]
        usedlag = bestlag
    else:
        usedlag = maxlag
        icbest = None
    if (regression != 'nc'):
        resols = OLS(xdshort, add_trend(xdall[:, :(usedlag + 1)], regression)).fit()
    else:
        resols = OLS(xdshort, xdall[:, :(usedlag + 1)]).fit()
    adfstat = resols.tvalues[0]
    pvalue = mackinnonp(adfstat, regression=regression, N=1)
    critvalues = mackinnoncrit(N=1, regression=regression, nobs=nobs)
    critvalues = {'1%': critvalues[0], '5%': critvalues[1], '10%': critvalues[2]}
    if store:
        resstore.resols = resols
        resstore.maxlag = maxlag
        resstore.usedlag = usedlag
        resstore.adfstat = adfstat
        resstore.critvalues = critvalues
        resstore.nobs = nobs
        resstore.H0 = 'The coefficient on the lagged level equals 1 - unit root'
        resstore.HA = 'The coefficient on the lagged level < 1 - stationary'
        resstore.icbest = icbest
        resstore._str = 'Augmented Dickey-Fuller Test Results'
        return (adfstat, pvalue, critvalues, resstore)
    elif (not autolag):
        return (adfstat, pvalue, usedlag, nobs, critvalues)
    else:
        return (adfstat, pvalue, usedlag, nobs, critvalues, icbest)
Augmented Dickey-Fuller unit root test

The Augmented Dickey-Fuller test can be used to test for a unit root in a
univariate process in the presence of serial correlation.

Parameters
----------
x : array_like, 1d
    data series
maxlag : int
    Maximum lag which is included in test, default 12*(nobs/100)^{1/4}
regression : {'c','ct','ctt','nc'}
    Constant and trend order to include in regression

    * 'c' : constant only (default)
    * 'ct' : constant and trend
    * 'ctt' : constant, and linear and quadratic trend
    * 'nc' : no constant, no trend
autolag : {'AIC', 'BIC', 't-stat', None}
    * if None, then maxlag lags are used
    * if 'AIC' (default) or 'BIC', then the number of lags is chosen
      to minimize the corresponding information criterion
    * 't-stat' based choice of maxlag.  Starts with maxlag and drops a
      lag until the t-statistic on the last lag length is significant
      using a 5%-sized test
store : bool
    If True, then a result instance is returned additionally to
    the adf statistic. Default is False
regresults : bool, optional
    If True, the full regression results are returned. Default is False

Returns
-------
adf : float
    Test statistic
pvalue : float
    MacKinnon's approximate p-value based on MacKinnon (1994, 2010)
usedlag : int
    Number of lags used
nobs : int
    Number of observations used for the ADF regression and calculation of
    the critical values
critical values : dict
    Critical values for the test statistic at the 1 %, 5 %, and 10 %
    levels. Based on MacKinnon (2010)
icbest : float
    The maximized information criterion if autolag is not None.
resstore : ResultStore, optional
    A dummy class with results attached as attributes

Notes
-----
The null hypothesis of the Augmented Dickey-Fuller is that there is a unit
root, with the alternative that there is no unit root. If the pvalue is
above a critical size, then we cannot reject that there is a unit root.

The p-values are obtained through regression surface approximation from
MacKinnon 1994, but using the updated 2010 tables. If the p-value is close
to significant, then the critical values should be used to judge whether
to reject the null.

The autolag option and maxlag for it are described in Greene.

Examples
--------
See example notebook

References
----------
.. [*] W. Green.  "Econometric Analysis," 5th ed., Pearson, 2003.

.. [*] Hamilton, J.D.  "Time Series Analysis".  Princeton, 1994.

.. [*] MacKinnon, J.G. 1994.  "Approximate asymptotic distribution functions for
    unit-root and cointegration tests.  `Journal of Business and Economic
    Statistics` 12, 167-76.

.. [*] MacKinnon, J.G. 2010. "Critical Values for Cointegration Tests."  Queen's
    University, Dept of Economics, Working Papers.  Available at
    http://ideas.repec.org/p/qed/wpaper/1227.html
def adfuller(x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False):
    '\n    Augmented Dickey-Fuller unit root test\n\n    The Augmented Dickey-Fuller test can be used to test for a unit root in a\n    univariate process in the presence of serial correlation.\n\n    Parameters\n    ----------\n    x : array_like, 1d\n        data series\n    maxlag : int\n        Maximum lag which is included in test, default 12*(nobs/100)^{1/4}\n    regression : {\'c\',\'ct\',\'ctt\',\'nc\'}\n        Constant and trend order to include in regression\n\n        * \'c\' : constant only (default)\n        * \'ct\' : constant and trend\n        * \'ctt\' : constant, and linear and quadratic trend\n        * \'nc\' : no constant, no trend\n    autolag : {\'AIC\', \'BIC\', \'t-stat\', None}\n        * if None, then maxlag lags are used\n        * if \'AIC\' (default) or \'BIC\', then the number of lags is chosen\n          to minimize the corresponding information criterion\n        * \'t-stat\' based choice of maxlag.  Starts with maxlag and drops a\n          lag until the t-statistic on the last lag length is significant\n          using a 5%-sized test\n    store : bool\n        If True, then a result instance is returned additionally to\n        the adf statistic. Default is False\n    regresults : bool, optional\n        If True, the full regression results are returned. Default is False\n\n    Returns\n    -------\n    adf : float\n        Test statistic\n    pvalue : float\n        MacKinnon\'s approximate p-value based on MacKinnon (1994, 2010)\n    usedlag : int\n        Number of lags used\n    nobs : int\n        Number of observations used for the ADF regression and calculation of\n        the critical values\n    critical values : dict\n        Critical values for the test statistic at the 1 %, 5 %, and 10 %\n        levels. Based on MacKinnon (2010)\n    icbest : float\n        The maximized information criterion if autolag is not None.\n    resstore : ResultStore, optional\n        A dummy class with results attached as attributes\n\n    Notes\n    -----\n    The null hypothesis of the Augmented Dickey-Fuller is that there is a unit\n    root, with the alternative that there is no unit root. If the pvalue is\n    above a critical size, then we cannot reject that there is a unit root.\n\n    The p-values are obtained through regression surface approximation from\n    MacKinnon 1994, but using the updated 2010 tables. If the p-value is close\n    to significant, then the critical values should be used to judge whether\n    to reject the null.\n\n    The autolag option and maxlag for it are described in Greene.\n\n    Examples\n    --------\n    See example notebook\n\n    References\n    ----------\n    .. [*] W. Green.  "Econometric Analysis," 5th ed., Pearson, 2003.\n\n    .. [*] Hamilton, J.D.  "Time Series Analysis".  Princeton, 1994.\n\n    .. [*] MacKinnon, J.G. 1994.  "Approximate asymptotic distribution functions for\n        unit-root and cointegration tests.  `Journal of Business and Economic\n        Statistics` 12, 167-76.\n\n    .. [*] MacKinnon, J.G. 2010. "Critical Values for Cointegration Tests."  Queen\'s\n        University, Dept of Economics, Working Papers.  Available at\n        http://ideas.repec.org/p/qed/wpaper/1227.html\n    '
    if regresults:
        store = True
    trenddict = {None: 'nc', 0: 'c', 1: 'ct', 2: 'ctt'}
    if ((regression is None) or isinstance(regression, (int, long))):
        regression = trenddict[regression]
    regression = regression.lower()
    if (regression not in ['c', 'nc', 'ct', 'ctt']):
        raise (ValueError('regression option %s not understood') % regression)
    x = np.asarray(x)
    nobs = x.shape[0]
    if (maxlag is None):
        maxlag = int(np.ceil((12.0 * np.power((nobs / 100.0), (1 / 4.0)))))
    xdiff = np.diff(x)
    xdall = lagmat(xdiff[:, None], maxlag, trim='both', original='in')
    nobs = xdall.shape[0]
    xdall[:, 0] = x[((- nobs) - 1):(- 1)]
    xdshort = xdiff[(- nobs):]
    if store:
        resstore = ResultsStore()
    if autolag:
        if (regression != 'nc'):
            fullRHS = add_trend(xdall, regression, prepend=True)
        else:
            fullRHS = xdall
        startlag = ((fullRHS.shape[1] - xdall.shape[1]) + 1)
        if (not regresults):
            (icbest, bestlag) = _autolag(OLS, xdshort, fullRHS, startlag, maxlag, autolag)
        else:
            (icbest, bestlag, alres) = _autolag(OLS, xdshort, fullRHS, startlag, maxlag, autolag, regresults=regresults)
            resstore.autolag_results = alres
        bestlag -= startlag
        xdall = lagmat(xdiff[:, None], bestlag, trim='both', original='in')
        nobs = xdall.shape[0]
        xdall[:, 0] = x[((- nobs) - 1):(- 1)]
        xdshort = xdiff[(- nobs):]
        usedlag = bestlag
    else:
        usedlag = maxlag
        icbest = None
    if (regression != 'nc'):
        resols = OLS(xdshort, add_trend(xdall[:, :(usedlag + 1)], regression)).fit()
    else:
        resols = OLS(xdshort, xdall[:, :(usedlag + 1)]).fit()
    adfstat = resols.tvalues[0]
    pvalue = mackinnonp(adfstat, regression=regression, N=1)
    critvalues = mackinnoncrit(N=1, regression=regression, nobs=nobs)
    critvalues = {'1%': critvalues[0], '5%': critvalues[1], '10%': critvalues[2]}
    if store:
        resstore.resols = resols
        resstore.maxlag = maxlag
        resstore.usedlag = usedlag
        resstore.adfstat = adfstat
        resstore.critvalues = critvalues
        resstore.nobs = nobs
        resstore.H0 = 'The coefficient on the lagged level equals 1 - unit root'
        resstore.HA = 'The coefficient on the lagged level < 1 - stationary'
        resstore.icbest = icbest
        resstore._str = 'Augmented Dickey-Fuller Test Results'
        return (adfstat, pvalue, critvalues, resstore)
    elif (not autolag):
        return (adfstat, pvalue, usedlag, nobs, critvalues)
    else:
        return (adfstat, pvalue, usedlag, nobs, critvalues, icbest)