Discussion:
[pystatsmodels] Predicting values with AR model
Georgios Boumis
2018-10-14 20:36:25 UTC
Permalink
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?

[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-14 23:02:39 UTC
Permalink
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering and
forecasting. There are questions and examples in the issues, but I'm not
very familiar with them.

In contrast to the premade models, I had spent some time adding supporting
code for "theoretical", hand calculated exercises in arima_process.
However, that does not directly include forecasting.

e.g. to get the SAR process and some of its properties (still seems to work
after 9 years)

import statsmodels.tsa.arima_process as ap

# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])

# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])

# combined process
ar_2s1 = arp2 * arp_seas

ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs

# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-14 23:18:33 UTC
Permalink
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering and
forecasting. There are questions and examples in the issues, but I'm not
very familiar with them.
In contrast to the premade models, I had spent some time adding supporting
code for "theoretical", hand calculated exercises in arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
IIUC, not having looked at this in many years
the variance of the forecast error should be something like this

var_coeffs = ar_2s1.arma2ma(24)**2
var_resid = 7**2
np.cumsum(var_coeffs) * var_resid

1-step ahead forecast brute force is something like

y_tplus1 = ar_2s1.arcoefs.dot(y_lagged)
<update y_lagged>
y_tplus1 = ar_2s1.arcoefs.dot(y_lagged_tplus1)

(I don't remember the lfilter version)

Josef
Post by j***@gmail.com
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-14 23:21:26 UTC
Permalink
Post by j***@gmail.com
On Sun, Oct 14, 2018 at 4:36 PM Georgios Boumis <
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering and
forecasting. There are questions and examples in the issues, but I'm not
very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
IIUC, not having looked at this in many years
the variance of the forecast error should be something like this
without parameter uncertainty
Post by j***@gmail.com
var_coeffs = ar_2s1.arma2ma(24)**2
var_resid = 7**2
np.cumsum(var_coeffs) * var_resid
1-step ahead forecast brute force is something like
y_tplus1 = ar_2s1.arcoefs.dot(y_lagged)
<update y_lagged>
y_tplus1 = ar_2s1.arcoefs.dot(y_lagged_tplus1)
(I don't remember the lfilter version)
Josef
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
Georgios Boumis
2018-10-15 10:40:14 UTC
Permalink
Thank you very much for your quick response and help. I just don't get why
you give the MA representation 20 lags when this ARMA is (14,0). Shouldn't
we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?


΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering and
forecasting. There are questions and examples in the issues, but I'm not
very familiar with them.
In contrast to the premade models, I had spent some time adding supporting
code for "theoretical", hand calculated exercises in arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-15 11:21:59 UTC
Permalink
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get why
you give the MA representation 20 lags when this ARMA is (14,0). Shouldn't
we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.

The MA representation of an AR process has an infinite number of lags but
will be negligible after some lags. However, with a large coefficient 0.95
at the seasonal lag, the MA will still be large after several years, i.e.
k * 12 for several k should be large.

The MA representation is the same as the impulse response function, and you
could plot those properties with nobs/klags over several years to see their
long term behavior.

Somewhere there might still be a plot function that I had used, IIRC, a 4
plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.

Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering and
forecasting. There are questions and examples in the issues, but I'm not
very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
Georgios Boumis
2018-10-15 13:31:51 UTC
Permalink
Thank you! Now I get! So for my case let's say I use MA(15) (which is not
the best one since the ψ parameters are still far from zero) but that
doesn't not affect the variance I need to calculate for the 95% interval
because I will only use the first 2 ψ right?

[image: ΣτιγΌιότυπο 2018-10-15, 3.27.40 ΌΌ.png]

΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:22:11 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get
why you give the MA representation 20 lags when this ARMA is (14,0).
Shouldn't we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.
The MA representation of an AR process has an infinite number of lags but
will be negligible after some lags. However, with a large coefficient 0.95
at the seasonal lag, the MA will still be large after several years, i.e.
k * 12 for several k should be large.
The MA representation is the same as the impulse response function, and
you could plot those properties with nobs/klags over several years to see
their long term behavior.
Somewhere there might still be a plot function that I had used, IIRC, a 4
plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.
Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering
and forecasting. There are questions and examples in the issues, but I'm
not very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-15 13:37:10 UTC
Permalink
Post by Georgios Boumis
Thank you! Now I get! So for my case let's say I use MA(15) (which is not
the best one since the ψ parameters are still far from zero) but that
doesn't not affect the variance I need to calculate for the 95% interval
because I will only use the first 2 ψ right?
yes, because your question is only for a forecast horizon of 2.
However, my cumsum computation does this automatically for all forecast
horizons up to the number of MA terms. In your case you only need two MA
terms.

Josef
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-15, 3.27.40 ΌΌ.png]
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:22:11 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get
why you give the MA representation 20 lags when this ARMA is (14,0).
Shouldn't we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.
The MA representation of an AR process has an infinite number of lags but
will be negligible after some lags. However, with a large coefficient 0.95
at the seasonal lag, the MA will still be large after several years, i.e.
k * 12 for several k should be large.
The MA representation is the same as the impulse response function, and
you could plot those properties with nobs/klags over several years to see
their long term behavior.
Somewhere there might still be a plot function that I had used, IIRC, a 4
plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.
Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a
AR model with know phi parameters. How can I predict the next 2 values
using statsmodels? It seems that it can only be predicted if you fit a
model to your data. But now that I already know the model, is it possible
to predict in python?
SARIMAX can take predefined parameters and use them for the filtering
and forecasting. There are questions and examples in the issues, but I'm
not very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
Georgios Boumis
2018-10-15 13:51:43 UTC
Permalink
Yeah exactly!!! Thank you very much for your support. Btw, I'm currently a
masters student. May I ask your profession?

΀η Δευτέρα, 15 Οκτωβρίου 2018 - 3:37:25 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you! Now I get! So for my case let's say I use MA(15) (which is not
the best one since the ψ parameters are still far from zero) but that
doesn't not affect the variance I need to calculate for the 95% interval
because I will only use the first 2 ψ right?
yes, because your question is only for a forecast horizon of 2.
However, my cumsum computation does this automatically for all forecast
horizons up to the number of MA terms. In your case you only need two MA
terms.
Josef
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-15, 3.27.40 ΌΌ.png]
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:22:11 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get
why you give the MA representation 20 lags when this ARMA is (14,0).
Shouldn't we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.
The MA representation of an AR process has an infinite number of lags
but will be negligible after some lags. However, with a large coefficient
0.95 at the seasonal lag, the MA will still be large after several years,
i.e. k * 12 for several k should be large.
The MA representation is the same as the impulse response function, and
you could plot those properties with nobs/klags over several years to see
their long term behavior.
Somewhere there might still be a plot function that I had used, IIRC, a
4 plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.
Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a
AR model with know phi parameters. How can I predict the next 2 values
using statsmodels? It seems that it can only be predicted if you fit a
model to your data. But now that I already know the model, is it possible
to predict in python?
SARIMAX can take predefined parameters and use them for the filtering
and forecasting. There are questions and examples in the issues, but I'm
not very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-15 14:22:43 UTC
Permalink
Post by Georgios Boumis
Yeah exactly!!! Thank you very much for your support. Btw, I'm currently a
masters student. May I ask your profession?
My academic training was mostly in economics switching between applied
econometrics and economic theory/industrial organization. But I learned a
bit of statistics as used in other fields in the last 10 years.
(My undergraduate/master was half computer science and half
economics/econometrics. My PhD got too close to math-econ.)

Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 3:37:25 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you! Now I get! So for my case let's say I use MA(15) (which is
not the best one since the ψ parameters are still far from zero) but that
doesn't not affect the variance I need to calculate for the 95% interval
because I will only use the first 2 ψ right?
yes, because your question is only for a forecast horizon of 2.
However, my cumsum computation does this automatically for all forecast
horizons up to the number of MA terms. In your case you only need two MA
terms.
Josef
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-15, 3.27.40 ΌΌ.png]
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:22:11 ÎŒ.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get
why you give the MA representation 20 lags when this ARMA is (14,0).
Shouldn't we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.
The MA representation of an AR process has an infinite number of lags
but will be negligible after some lags. However, with a large coefficient
0.95 at the seasonal lag, the MA will still be large after several years,
i.e. k * 12 for several k should be large.
The MA representation is the same as the impulse response function, and
you could plot those properties with nobs/klags over several years to see
their long term behavior.
Somewhere there might still be a plot function that I had used, IIRC, a
4 plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.
Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a
AR model with know phi parameters. How can I predict the next 2 values
using statsmodels? It seems that it can only be predicted if you fit a
model to your data. But now that I already know the model, is it possible
to predict in python?
SARIMAX can take predefined parameters and use them for the filtering
and forecasting. There are questions and examples in the issues, but I'm
not very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems
to work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
j***@gmail.com
2018-10-15 13:32:59 UTC
Permalink
Post by j***@gmail.com
Post by Georgios Boumis
Thank you very much for your quick response and help. I just don't get
why you give the MA representation 20 lags when this ARMA is (14,0).
Shouldn't we use ar_2s1.arma2ma(15) instead? 14+1(zero lag)?
The number of terms (nobs=20) that I put in there were just for checking.
The MA representation of an AR process has an infinite number of lags but
will be negligible after some lags. However, with a large coefficient 0.95
at the seasonal lag, the MA will still be large after several years, i.e.
k * 12 for several k should be large.
The MA representation is the same as the impulse response function, and
you could plot those properties with nobs/klags over several years to see
their long term behavior.
Somewhere there might still be a plot function that I had used, IIRC, a 4
plot grid with ACF, PACF, impulse response and periodogram or spectral
density for an ArmaProcess.
to point to another class written for "theoretical" exercises:
statsmodels.sandbox.tsa.fftarma.ArmaFft
It has a plot4 method.

The class was intended to get all the ARMA properties in frequency domain,
and using FFT for most computation.
This one never got beyond the initial experimental stage because I wasn't
sure about some definitions, and I didn't know of any other package that
has this and could have been used to write unit test and check some
definitions and scalings.

This was one of my code for "I wish I had those functions when I was a
student and had to do theoretical exercised or exercises with computation
by hand ."

Josef
Post by j***@gmail.com
Josef
Post by Georgios Boumis
΀η Δευτέρα, 15 Οκτωβρίου 2018 - 1:02:55 π.ÎŒ. UTC+2, ο χρήστης josefpktd
Post by j***@gmail.com
Post by Georgios Boumis
I have been given 16 observations which I already know they follow a AR
model with know phi parameters. How can I predict the next 2 values using
statsmodels? It seems that it can only be predicted if you fit a model to
your data. But now that I already know the model, is it possible to predict
in python?
SARIMAX can take predefined parameters and use them for the filtering
and forecasting. There are questions and examples in the issues, but I'm
not very familiar with them.
In contrast to the premade models, I had spent some time adding
supporting code for "theoretical", hand calculated exercises in
arima_process.
However, that does not directly include forecasting.
e.g. to get the SAR process and some of its properties (still seems to
work after 9 years)
import statsmodels.tsa.arima_process as ap
# seasonal lag polynomial and process
ar_seas = ap.index2lpol([1, -0.95], [0, 12])
arp_seas = ap.ArmaProcess(ar_seas, [1])
# AR(2) lag polynomial and process
ar2 = [1, -0.5, 0.5]
arp2 = ap.ArmaProcess(ar2, [1])
# combined process
ar_2s1 = arp2 * arp_seas
ar_2s1.ar
ar_2s1.arma2ma(20)
ar_2s1.arcoefs
# extras
ar_2s1.arroots
ar_2s1.pacf(12*2)
ar_2s1.periodogram(12*4)
Post by Georgios Boumis
[image: ΣτιγΌιότυπο 2018-10-14, 10.35.41 ΌΌ.png]
Continue reading on narkive:
Loading...