Dear Tom, About the AR(1) component, you suggested last time that:
TomDoan wrote:Jennylai wrote:Dear Tom,
I tried to incorporate AR(1) part into the state vectors, and I just revised a little bit of the program durkp162 by adding M3 into Nonlin:
nonlin phil phis v1
frml m3=v1/sqrt(1+v1*v1)
.
.
.
dlm(method=bfgs,start=(a=al~\M3~\as,sw=exp(2*phil)*swl~\exp(2*phis)*sws),$
y=FDI,a=a,c=c,exact,scale,sv=1.0,sw=sw,type=filter) / xfilter
"
But it does not work. May I ask how to incorporate this AR(1) part into the model? Thank you!
- Code: Select all
frml m3=v1/sqrt(1+v1*v1)
You need a space before the equal sign.
- Code: Select all
dlm(method=bfgs,start=(a=al~\M3~\as,sw=exp(2*phil)*swl~\exp(2*phis)*sws),$
y=FDI,a=a,c=c,exact,scale,sv=1.0,sw=sw,type=filter) / xfilter
The dimension of SW is going to be wrong here. swl has the shocks to the linear trend model, sws has the shocks to the seasonal, but you need the variance to the shock to the AR in between them.
Also, make sure that your "C" matrix adds in the AR component.
Dear Tom,
I have another question concerning the AR(1) component being incorporated into the State Space Model.
I've applied what you mentioned last time to the programme, and the revised programme looks like this:
open plot originalFDI.rgf
graph(footer="Figure 1 Monthly FDI inflows to China")
# FDI
close plot
*
* Generate the basic seasonal and local level component models
* SeasonalDLM and LocalDLM create the "A", "C" and "SW" matrices (in RATS notation)
*
@SeasonalDLM(type=fourier) as cs sws
@LocalDLM(type=trend) al cl swl
*
* Add the AR(1) part in to the matrix "C"
compute ca=||1.0||
*
* 'Glue' cl,ca and cs together. As Matrix "A" and "SW" will have unknown parameters,
* we will glue them inside the 'DLM' command.
*
compute c=cl~~ca~~cs
*
* Generate the 'SW' matrix for AR(1) component.
compute swa=||1.0||
*
*
nonlin phil phis rov phia
*
* The success of the estimation is quite sensitive to the initial guess values.
* The following is a bit cruder than the guess values computed using the
* reference in the book, but should work in practice
*
* (a) get rid of the seasonal by regression. (This corresponds to
* a zero variance for that component)
*
filter(remove=seasonal) FDI / deseas
*
* (b) do a short span filter on the deseasonalized data to get an
* estimate of the local trend
*
filter(type=centered,width=5) deseas / trend
*
* (c) compute the approximate irregular component and its variance
*
set irreg = deseas-trend
stats(noprint) irreg
compute vi=%variance
*
* (d) compute the first difference of the local level component and
* its variance
*
set difft = trend-trend{1}
stats(noprint) difft
compute vl=%variance
*
* Because we're concentrating out the irregular variance, the "phil" parameter
* needs to be initialized based upon the ratio. We'll make "phis" small.
*
* Set the initial values for 'phil','phis',and 'v3','va'.
*
compute v3=0
compute va=0
*
compute phil=log(sqrt(vl/vi))
compute phis=-4.0
compute rov=v3/sqrt(1+v3*v3)
compute phia=log(sqrt(va/vi))
*
* Generage the 'G' option for 'Exact' initialization to perform.
*
compute g=%zeros(1,%rows(c))
compute g(1,3)=1.0
*
* Because the A and SW matrix for the complete model depend upon the parameters being
* estimated, we couldn't "glue" it together earlier.
*
dlm(method=bfgs,start=(a=al~~rov~~as,sw=exp(2*phil)*swl~\exp(2*phia)*swa~\exp(2*phis)*sws),$
y=FDI,a=a,c=c,exact,g=g,scale,sv=1.0,sw=sw,type=filter) / xfilter pfilter
However, it does not work in RATS, and RATS reports the error like this:
dlm(method=bfgs,start=(a=al~~rov~~as,<<<<
## SX20. Expected ) Here
>>>>sw=exp(2*phil)*swl~\exp(2*phia)*swa~\exp(2*phis)*sws),$
y=FDI,a=a,c=c,exact,g=g,scale,sv=1.0,sw=sw,type=filter) / xfilter pfilter
Is it the case that RATS does not allow two expression inside the 'START' option in 'DLM' command?