From: Kirk Hammett on
Hello,
I am new to Matlab as well as time series analysis. I usually use R for stats but wanted to dip into Matlab waters. My question is that I have data that I need to fit AR(1) and MA(1) models to. I need it to use the MLE method. In R I could have used ar.mle() but the closest function I found in Matlab was garchfit(). In general, I want to be able to fit any ARMA(p,q) model to data. I am looking at garchfit() to do this however I don't know how to specify the above models in Matlab. It would be great if I could get an example of say ARMA(2,1) fit to data using garchfit().
Thank you.
From: Wayne King on
"Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpbma4$j46$1(a)fred.mathworks.com>...
> Hello,
> I am new to Matlab as well as time series analysis. I usually use R for stats but wanted to dip into Matlab waters. My question is that I have data that I need to fit AR(1) and MA(1) models to. I need it to use the MLE method. In R I could have used ar.mle() but the closest function I found in Matlab was garchfit(). In general, I want to be able to fit any ARMA(p,q) model to data. I am looking at garchfit() to do this however I don't know how to specify the above models in Matlab. It would be great if I could get an example of say ARMA(2,1) fit to data using garchfit().
> Thank you.

Hi Kirk, do you have the System Identification Toolbox. If so, then you can use armax()

>>doc armax

Wayne
From: Kirk Hammett on
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hpc028$1ib$1(a)fred.mathworks.com>...
> "Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpbma4$j46$1(a)fred.mathworks.com>...
> > Hello,
> > I am new to Matlab as well as time series analysis. I usually use R for stats but wanted to dip into Matlab waters. My question is that I have data that I need to fit AR(1) and MA(1) models to. I need it to use the MLE method. In R I could have used ar.mle() but the closest function I found in Matlab was garchfit(). In general, I want to be able to fit any ARMA(p,q) model to data. I am looking at garchfit() to do this however I don't know how to specify the above models in Matlab. It would be great if I could get an example of say ARMA(2,1) fit to data using garchfit().
> > Thank you.
>
> Hi Kirk, do you have the System Identification Toolbox. If so, then you can use armax()
>
> >>doc armax
>
> Wayne

Hi Wayne. I actually looked at the documentation for armax(). However from what I understood, it does not use the MLE method which I want. I think it uses OLS which is pretty close. But I want to learn how to use garchfit() as it seems like a swiss army knife for this kind of stuff.
From: Wayne King on
"Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpc1rj$oot$1(a)fred.mathworks.com>...
> "Wayne King" <wmkingty(a)gmail.com> wrote in message <hpc028$1ib$1(a)fred.mathworks.com>...
> > "Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpbma4$j46$1(a)fred.mathworks.com>...
> > > Hello,
> > > I am new to Matlab as well as time series analysis. I usually use R for stats but wanted to dip into Matlab waters. My question is that I have data that I need to fit AR(1) and MA(1) models to. I need it to use the MLE method. In R I could have used ar.mle() but the closest function I found in Matlab was garchfit(). In general, I want to be able to fit any ARMA(p,q) model to data. I am looking at garchfit() to do this however I don't know how to specify the above models in Matlab. It would be great if I could get an example of say ARMA(2,1) fit to data using garchfit().
> > > Thank you.
> >
> > Hi Kirk, do you have the System Identification Toolbox. If so, then you can use armax()
> >
> > >>doc armax
> >
> > Wayne
>
> Hi Wayne. I actually looked at the documentation for armax(). However from what I understood, it does not use the MLE method which I want. I think it uses OLS which is pretty close. But I want to learn how to use garchfit() as it seems like a swiss army knife for this kind of stuff.

Hi Kirk, how about this:

% create an ARMA(2,1) model in Matlab
B = [1 0.5];
A =[1 -0.9 0.7];
reset(RandStream.getDefaultStream);
y = filter(B,A,randn(1000,1));
spec = garchset('R', 2, 'M', 1,'variancemodel','constant');
[Coeff,Errors] = garchfit(spec,y);

garchfit() returns the model
y(n)= -0.0482+0.9645*y(n-1)-0.7435*y(n-2)+e(n)+0.4659*e(n-1)

Which is very close to the model used in filter()

y(n)=0.9*y(n-1)-0.7*y(n-2)+e(n)+0.5*x(n-1)


If you want to fit just AR(p) models, then check out aryule(), arburg().

Wayne
From: Kirk Hammett on
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hpcd93$rp6$1(a)fred.mathworks.com>...
> "Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpc1rj$oot$1(a)fred.mathworks.com>...
> > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hpc028$1ib$1(a)fred.mathworks.com>...
> > > "Kirk Hammett" <leprekhan(a)yahoo.com> wrote in message <hpbma4$j46$1(a)fred.mathworks.com>...
> > > > Hello,
> > > > I am new to Matlab as well as time series analysis. I usually use R for stats but wanted to dip into Matlab waters. My question is that I have data that I need to fit AR(1) and MA(1) models to. I need it to use the MLE method. In R I could have used ar.mle() but the closest function I found in Matlab was garchfit(). In general, I want to be able to fit any ARMA(p,q) model to data. I am looking at garchfit() to do this however I don't know how to specify the above models in Matlab. It would be great if I could get an example of say ARMA(2,1) fit to data using garchfit().
> > > > Thank you.
> > >
> > > Hi Kirk, do you have the System Identification Toolbox. If so, then you can use armax()
> > >
> > > >>doc armax
> > >
> > > Wayne
> >
> > Hi Wayne. I actually looked at the documentation for armax(). However from what I understood, it does not use the MLE method which I want. I think it uses OLS which is pretty close. But I want to learn how to use garchfit() as it seems like a swiss army knife for this kind of stuff.
>
> Hi Kirk, how about this:
>
> % create an ARMA(2,1) model in Matlab
> B = [1 0.5];
> A =[1 -0.9 0.7];
> reset(RandStream.getDefaultStream);
> y = filter(B,A,randn(1000,1));
> spec = garchset('R', 2, 'M', 1,'variancemodel','constant');
> [Coeff,Errors] = garchfit(spec,y);
>
> garchfit() returns the model
> y(n)= -0.0482+0.9645*y(n-1)-0.7435*y(n-2)+e(n)+0.4659*e(n-1)
>
> Which is very close to the model used in filter()
>
> y(n)=0.9*y(n-1)-0.7*y(n-2)+e(n)+0.5*x(n-1)
>
>
> If you want to fit just AR(p) models, then check out aryule(), arburg().
>
> Wayne

Thank you! This is very helpful!