Setting number of lags

Viewed 44

I am teaching myself the use of time series in Python.

I was following

https://arch.readthedocs.io/en/latest/unitroot/unitroot_examples.html

I performed


adf = ADF(default)
print(adf.summary().as_text())

It worked perfectly.

However, when I wanted to change lags like

adf.lags = 5
print(adf.summary().as_text())

or change the type of trend as in the snip below

enter image description here

it gives me the following error (same for the trend):

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [11], in <module>
----> 1 adf.lags = 5
      2 print(adf.summary().as_text())

AttributeError: can't set attribute



Even when I follow all instructions on the exercise page and recreate it with the data used there I cannot get the lags to change. What am I doing wrong?

1 Answers

Although documentation (r.t.docs) confirms as you suggested, after a quick look at ADF class inside ARCH/ unitroot/unitroot.py, I believe it takes parameter lags upon creation of the class. I tried and it works. Instead of adf.lags = 5 you may use version below.

adf = ADF(default, lags = 5 )

class ADF:

def __init__(
    self,
    y: ArrayLike,
    lags: Optional[int] = None,
    trend: UnitRootTrend = "c",
    max_lags: Optional[int] = None,
    method: Literal["aic", "bic", "t-stat"] = "aic",
    low_memory: Optional[bool] = None,
) -> None:
Related