# AR model

8 messages
Open this post in threaded view
|

## AR model

 Good eveningI have a doubt on polynomials. If I have an AR model like Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding polynomial, would it be [1 -b1 -b2]?Thank you very much.Kind regards, Estefanía
Open this post in threaded view
|

## Re: AR model

 On 04.07.2020 21:37, [hidden email] wrote: > Good evening > > I have a doubt on polynomials. If I have an AR model like > Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding > polynomial, would it be [1 -b1 -b2]? > > Thank you very much. > > Kind regards, > > Estefanía > > polynomials have positive exponents. You seems to use negative ones b0+b1*Yt^-1+b2*Yt^-2 so they are not polynomial https://octave.org/doc/v5.2.0/Polynomial-Manipulations.htmlMarco
Open this post in threaded view
|

## Re: AR model

 please reply to the mailing list On 04.07.2020 22:25, [hidden email] wrote: > Thank you for your answer. > The fact is that yt=b0+b1*y^-1+b2*y^-2 is also written as (1-b1-b2)*L > being L the lag operator. This is why I wrote [1 -b1 -b2]. > > I want to find the roots of the corresponding polynomial for that AR > model. Should then I put: [1 b1 b2]? I find examples for polynomials > like x^2+x+1, for instance, but I need the way to express an AR model. > Could you help me? Thank you very much. > > Kind regards, > > Estefanía > I am not an expert in AR model, but taking the definition at https://en.wikipedia.org/wiki/Autoregressive_modelit seems not a simple polynomial operation. The TSA package as some functions https://octave.sourceforge.io/tsa/overview.htmlthat is referring to AR. You may want it, of clarify better what you want to meet. > El sáb., 4 jul. 2020 22:12, Marco Atzeri <[hidden email] > > escribió: > >     On 04.07.2020 21:37, [hidden email] >     wrote: >      > Good evening >      > >      > I have a doubt on polynomials. If I have an AR model like >      > Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding >      > polynomial, would it be [1 -b1 -b2]? >      > >      > Thank you very much. >      > >      > Kind regards, >      > >      > Estefanía >      > >      > > >     polynomials have positive exponents. >     You seems to use negative ones b0+b1*Yt^-1+b2*Yt^-2 > >     so they are not polynomial > >     https://octave.org/doc/v5.2.0/Polynomial-Manipulations.html> >     Marco > > >
Open this post in threaded view
|

## Re: AR model

 In reply to this post by marco atzeri-2 > > I have a doubt on polynomials. If I have an AR model like > > Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding > > polynomial, would it be [1 -b1 -b2]? > You seems to use negative ones b0+b1*Yt^-1+b2*Yt^-2 > so they are not polynomial The polynomial representation is not the delayed representation, in estefania's x^{-2} means x(t-2*dt), that is the value of the signals two timesteps in the past. This is a operator representation. the corresponding polynomial would be x = a x^{-2} --> x(t) = a x(t-2*dt), so the coefficients are the same. @estefania: Yt=b0+b1*Yt-1+b2*Yt-2+et is then y(t) = b0 + b1 * y(t-1) + b2 * y(t-2) + noise(t) and the polynomial is py = [b2 b1 b0] if you want to solve the coefficients that minimize the squared error (i.e. is the same as assuming noise is i.i.d. and sampled from a Gaussian distribution) you can do (for one data set) # assumes x is a column vector containing the signal, with length N X = [x(1:end-2) x(2:end-1) ones(N-2,1)]; # this is the Vandermonde matrix in operator space py = X \ x(3:N) Example: # create synthetic data N = 10; x_noiseless = x = zeros (N, 1); x_noiseless(1) = 0.0; x_noiseless(2) = 0.0; px_true = [0.2 -0.5 0.1].'; pdeg = length(px_true) - 1; # polynomial's degree for i = 3:N     x_noiseless(i) = px_true(3) + x_noiseless(i-1) * px_true(2) + x_noiseless(i-2) * px_true(1);     # alternative, and more generic     # x_noiseless(i) = [x((i-pdeg):(i-1)).' 1] * px_true; endfor x = x_noiseless + 0.01 * randn(N, 1); # add Gaussian noise # Solve with least-squares (check other functions in optim package, and other optimizations functions) X = [x(1:N-2) x(2:N-1) ones(N-2,1)]; px = X \ x(3:N); printf ('px_true and px_ols\n'); disp([px_true px]) # Compare x_ = zeros(N, 1); for i =3:N     x_(i) = [x((i-pdeg):(i-1)).' 1] * px; endfor plot(x,'o;data;', x_, 'x;estimation: mean value;') # end example You can vectorize the for loop using the function movslice, or if you implement your Ar model as a function you can use movfun. Check their help Regards,
Open this post in threaded view
|

## Re: AR model

 In reply to this post by marco atzeri-2 El sáb., 4 jul. 2020 22:25, <[hidden email]> escribió:Thank you for your answer. The fact is that yt=b0+b1*y^-1+b2*y^-2 is also written as (1-b1-b2)*L being L the lag operator. This is why I wrote [1 -b1 -b2].I want to find the roots of the corresponding polynomial for that AR model. Should then I put: [1 b1 b2]? I find examples for polynomials like x^2+x+1, for instance, but I need the way to express an AR model. Could you help me? Thank you very much. Kind regards, EstefaníaEl sáb., 4 jul. 2020 22:12, Marco Atzeri <[hidden email]> escribió:On 04.07.2020 21:37, [hidden email] wrote: > Good evening > > I have a doubt on polynomials. If I have an AR model like > Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding > polynomial, would it be [1 -b1 -b2]? > > Thank you very much. > > Kind regards, > > Estefanía > > polynomials have positive exponents. You seems to use negative ones b0+b1*Yt^-1+b2*Yt^-2 so they are not polynomial https://octave.org/doc/v5.2.0/Polynomial-Manipulations.html Marco
Open this post in threaded view
|

## Re: AR model

 In reply to this post by Juan Pablo Carbajal-2 Thank you! I just want to calculate the roots of the associated polynomial to an autoregressive model. If I put [b2 b1 b0], wouldn't it be b2*x^2+b*x+b0?, as Octave represents polynomials from highest to lowest degree. Can you help me?Best, EstefaníaEl dom., 5 jul. 2020 13:46, Juan Pablo Carbajal <[hidden email]> escribió:> > I have a doubt on polynomials. If I have an AR model like > > Yt=b0+b1*Yt-1+b2*Yt-2+et and I want to write the corresponding > > polynomial, would it be [1 -b1 -b2]? > You seems to use negative ones b0+b1*Yt^-1+b2*Yt^-2 > so they are not polynomial The polynomial representation is not the delayed representation, in estefania's x^{-2} means x(t-2*dt), that is the value of the signals two timesteps in the past. This is a operator representation. the corresponding polynomial would be x = a x^{-2} --> x(t) = a x(t-2*dt), so the coefficients are the same. @estefania: Yt=b0+b1*Yt-1+b2*Yt-2+et is then y(t) = b0 + b1 * y(t-1) + b2 * y(t-2) + noise(t) and the polynomial is py = [b2 b1 b0] if you want to solve the coefficients that minimize the squared error (i.e. is the same as assuming noise is i.i.d. and sampled from a Gaussian distribution) you can do (for one data set) # assumes x is a column vector containing the signal, with length N X = [x(1:end-2) x(2:end-1) ones(N-2,1)]; # this is the Vandermonde matrix in operator space py = X \ x(3:N) Example: # create synthetic data N = 10; x_noiseless = x = zeros (N, 1); x_noiseless(1) = 0.0; x_noiseless(2) = 0.0; px_true = [0.2 -0.5 0.1].'; pdeg = length(px_true) - 1; # polynomial's degree for i = 3:N     x_noiseless(i) = px_true(3) + x_noiseless(i-1) * px_true(2) + x_noiseless(i-2) * px_true(1);     # alternative, and more generic     # x_noiseless(i) = [x((i-pdeg):(i-1)).' 1] * px_true; endfor x = x_noiseless + 0.01 * randn(N, 1); # add Gaussian noise # Solve with least-squares (check other functions in optim package, and other optimizations functions) X = [x(1:N-2) x(2:N-1) ones(N-2,1)]; px = X \ x(3:N); printf ('px_true and px_ols\n'); disp([px_true px]) # Compare x_ = zeros(N, 1); for i =3:N     x_(i) = [x((i-pdeg):(i-1)).' 1] * px; endfor plot(x,'o;data;', x_, 'x;estimation: mean value;') # end example You can vectorize the for loop using the function movslice, or if you implement your Ar model as a function you can use movfun. Check their help Regards,