I'm trying to model my time series data using the AR model.
This is the code that I'm using.
# Compute AR-model (data is a python list of number)
model = AR(data)
result = model.fit()
plt.plot(data, 'b-', label='data')
plt.plot(range(result.k_ar, len(data)), result.fittedvalues, 'r-')
plt.show()
I've successfully get the p value using result.k_ar
, parameter with result.params
, epsilon term with result.sigma2
. The problem is that I can't find a way to get the c (constant) term. Here is the code I write to compare the result.
# Plot
fit = []
for t in range(result.k_ar, len(data)):
value = 0
for i in range(1, result.k_ar+1):
value += result.params[i-1] * data[t - i]
fit.append(value)
plt.plot(data, 'b-', label='data')
plt.plot(range(result.k_ar, len(data)), fit, 'r-', label='fit')
plt.plot(range(result.k_ar, len(data)), result.fittedvalues, 'r-')
plt.show()
My result and the result from result.fittedvalues
confirm my evident that there is some constant term added to the model. Thanks.
fit.append(value + result.sigma2
)? – Cusco