Page 2 of 3
Re: a question about state space model with exogenous regres
Posted: Sat Aug 10, 2013 3:58 pm
by fan
TomDoan wrote:You're still missing MU from your parameter set. You're also missing the SV for the measurement error. And, as I mentioned much earlier, if you use a non-zero multiplier on the "sentiment" variable in the measurement equation, you have to peg the variance of SW to 1. I would suggest that a simpler approach would be to make beta4=1 (so that C is just 1) and let SW be free as you have it written right now.
Dear Tom, thank you for pointing out my mistake.
following your suggestion, I made the following changes to my commands
frml c=||1.0||
frml sv=||se^2||
dlm(presample=ergodic,a=a,z=z,sw=sw,sv=sv,c=c,mu=lineareq,f=f,y=return,method=bfgs,type=filter)/ states0
Could you please kindly check the commands and point out my mistakes?
Many Thanks,
Fan
Re: a question about state space model with exogenous regres
Posted: Sat Aug 10, 2013 10:02 pm
by TomDoan
It looks fine. What's the problem?
Re: a question about state space model with exogenous regres
Posted: Sun Aug 11, 2013 3:37 am
by fan
TomDoan wrote:It looks fine. What's the problem?
Hi Tom. Could you kindly let me know what went wrong with me commands?
open data return(new).xls
cal(m) 1954
data(format=free, org=columns) 1954:4 2007:12 EVWRD EEWRD TERM DEFAULT DYIELD DEMOCRATIC
frml(reg,vector=b) lineareg EVWRD
# TERM{1} DEFAULT{1} DYIELD{1}
compute b=%zeros(3,1)
nonlin b ph1
frml a=||1.0||
frml z=||mu+ph1*democratic||
frml c=||1.0||
frml sw=||sn^2||
frml sv=||se^2||
compute f=||1.0||
dlm(presample=ergodic,a=a,z=z,sw=sw,sv=sv, mu=lineareq, c=c,f=f,y=return,method=bfgs,type=filter)/ states0
## IO9. Invalid input "ÐÏࡱ" on line 0 while processing series EVWRD entry 0
## IO30. There is no series EEWRD on the file
## IO30. There is no series TERM on the file
## IO30. There is no series DEFAULT on the file
## IO30. There is no series DYIELD on the file
## IO30. There is no series DEMOCRATIC on the file
## SX22. Expected Type FRML[ANY], Got RECTANGULAR[REAL] Instead
>>>>frml a=||1.0||<<<<
Re: a question about state space model with exogenous regres
Posted: Sun Aug 11, 2013 8:35 am
by TomDoan
That you're reading an Excel file as FORMAT=FREE?
If you've posted ten questions about a model for a data set that you haven't even read in yet, then you're doing empirical work backwards.
Re: a question about state space model with exogenous regres
Posted: Sun Aug 11, 2013 5:17 pm
by fan
TomDoan wrote:That you're reading an Excel file as FORMAT=FREE?
If you've posted ten questions about a model for a data set that you haven't even read in yet, then you're doing empirical work backwards.
Dear Tom,
I am truly sorry for posting so many questions here. I know most of my questions are simple and naïve. This is my first time using state space model and Rats program, so everything is new to me. Except the manual book, I have limited access to ask for help as most of my classmates they do not use Rats. You are my last resource for asking for help.
I tried the initial commands; however, they did not work. Based on error message, I made a small change to my commands. Still, the commands did not work. I checked the manual book to see how I can fix the error. Unfortunately, I did not the solution in the book. Therefore, could you please kindly take a look my commands and the error message and let me know where I did wrong?
B
est regards,
Sam
data(format=xls, org=columns) 1954:4 2007:12 EVWRD EEWRD TERM DEFAULT DYIELD DEMOCRATIC
frml(reg,vector=b) lineareg EVWRD
# TERM{1} DEFAULT{1} DYIELD{1}
compute b=%zeros(3,1)
dec frml real a z c sw sv
nonlin b ph1
frml a = 1.0
frml z = constant+ph1*democratic
frml c = 1.0
frml sw = sigsqeps
## SX11. Identifier SIGSQEPS is Not Recognizable. Incorrect Option Field or Parameter Order?
frml sv = ||se^2||
## SX11. Identifier SE is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>frml sv = ||se^<<<<
dlm(presample=ergodic,a=a,z=z,sw=sw,sv=sv, mu=lineareq, c=c,f=f,y=EVWRD,method=bfgs,type=filter)/ states0
Re: a question about state space model with exogenous regres
Posted: Mon Aug 12, 2013 7:54 pm
by TomDoan
What are SIGSQEPS and SE? I assume SIGSQEPS is supposed to be the variance in the state-space equation, since you have SW=SIGSQEPS, and that SE is supposed to be the standard deviation in the measurement equation since you have SV=SE^2. However, on your NONLIN, you have only
nonlin b ph1
That's supposed to list your free parameters. Where are SIGSQEPS and SE? Where's the MU that you had earlier in the Z? Why did you change a correct Z to one I already told you was incorrect?
Your first step should have been to read the data in, make sure it was correct, run the regression without the state-space error process to make sure it actually was the combination of series that you really intended, take the residuals and fit the simpler state-space model to that rather than running the combined model. If you had gone through those steps, you would already be done---with the final intended model. Trying to jump right in to a very complicated (small, but complicated) model is almost always a very bad plan.
Re: a question about state space model with exogenous regres
Posted: Tue Aug 13, 2013 2:03 am
by fan
TomDoan wrote:What are SIGSQEPS and SE? I assume SIGSQEPS is supposed to be the variance in the state-space equation, since you have SW=SIGSQEPS, and that SE is supposed to be the standard deviation in the measurement equation since you have SV=SE^2. However, on your NONLIN, you have only
nonlin b ph1
That's supposed to list your free parameters. Where are SIGSQEPS and SE? Where's the MU that you had earlier in the Z? Why did you change a correct Z to one I already told you was incorrect?
Your first step should have been to read the data in, make sure it was correct, run the regression without the state-space error process to make sure it actually was the combination of series that you really intended, take the residuals and fit the simpler state-space model to that rather than running the combined model. If you had gone through those steps, you would already be done---with the final intended model. Trying to jump right in to a very complicated (small, but complicated) model is almost always a very bad plan.
Dear Tom. Thank you for your advice. I will definitely do what you suggested. I was finally able to make my Rats commands work and get some results. However, I have a new question now. Could you please suggest how to give the initial values to my free parameters except assigning random values to them?
Best regards,
Fan
Re: a question about state space model with exogenous regres
Posted: Tue Aug 13, 2013 1:23 pm
by TomDoan
The obvious choice for the B's are a linear regression. You can combine steps by doing
linreg evwrd
# TERM{1} DEFAULT{1} DYIELD{1}
frml(lastreg,vector=b) lineareg evwrd
That way, the B will be initialized to the coefficients from the regression.
If you take the first difference of the residuals from that regression
set du = %resids-%resids{1}
then a regression of du on 1 and the dummy should give you rough guesses as to the two drift parameters. The residual variance from that regression (%seesq) should at least be in the right ballpark for a guess for the variance in the measurement equation. A guess at the variance of the state-space error would be some fraction of that variance, perhaps .001*%seesq.
Re: a question about state space model with exogenous regres
Posted: Tue Aug 13, 2013 5:52 pm
by fan
TomDoan wrote:The obvious choice for the B's are a linear regression. You can combine steps by doing
linreg evwrd
# TERM{1} DEFAULT{1} DYIELD{1}
frml(lastreg,vector=b) lineareg evwrd
That way, the B will be initialized to the coefficients from the regression.
If you take the first difference of the residuals from that regression
set du = %resids-%resids{1}
then a regression of du on 1 and the dummy should give you rough guesses as to the two drift parameters. The residual variance from that regression (%seesq) should at least be in the right ballpark for a guess for the variance in the measurement equation. A guess at the variance of the state-space error would be some fraction of that variance, perhaps .001*%seesq.
Thank you, Tom. Finally, I did one thing right this time. Thank you once again
Re: a question about state space model with exogenous regres
Posted: Mon Aug 19, 2013 7:15 pm
by fan
TomDoan wrote:The obvious choice for the B's are a linear regression. You can combine steps by doing
linreg evwrd
# TERM{1} DEFAULT{1} DYIELD{1}
frml(lastreg,vector=b) lineareg evwrd
That way, the B will be initialized to the coefficients from the regression.
If you take the first difference of the residuals from that regression
set du = %resids-%resids{1}
then a regression of du on 1 and the dummy should give you rough guesses as to the two drift parameters. The residual variance from that regression (%seesq) should at least be in the right ballpark for a guess for the variance in the measurement equation. A guess at the variance of the state-space error would be some fraction of that variance, perhaps .001*%seesq.
Dear Tom. Thank you for your suggestions about how to assign the initial values for my model. I have a new question would like to ask. I am sorry to posting new questions. If I would like to know the estimated coefficient of the state factor in my model, in other words, the C matrix is no longer fixed at one, how I can do it. I understand that as you pointed out earlier that I will need the variance of transition equation to be pegged to 1 to avoid a lack of identification between coefficient and that variance. I have tried several ways to peg the variation of transition to 1, such as fix SW=1.0 or fix SN=1.0. However, I could not make the Rats to work. Could you kindly suggest me what steps I need to take in order to get the estimated coefficient of the state variable in my model.
Best regards,
Fan
Re: a question about state space model with exogenous regres
Posted: Mon Aug 19, 2013 9:49 pm
by TomDoan
It has to be SW, not SV---the scale of SV is determined by the scale of the data.
You would need to add the coefficient on the state to your parameter set, take the variance of SW out of the parameter set, then change the formulas to
frml c = your_coefficient_name
frml sw = 1.0
I'm not sure why you want to do this, because it's much harder to come up with guess values for the parameters in that form---the C=1 is much more natural.
By the way, it doesn't help me for you to say "I couldn't get RATS to work". Show me what you did and tell me what happened.
Re: a question about state space model with exogenous regres
Posted: Fri Jan 24, 2014 3:29 am
by fan
Dear Tom, the following is my state-space model and the reduced form equation based on the state-space model
Measurement Eq.
R(t+1)=Constant+β1*X(1,t)+β2*X(2,t)+X(3,t+1)+ε(t+1)
Transition Eq.
X(3,t)=∅*X(3,t-1)+θ*Dummy(t)-(∅*θ)Dummy(t-1)+ηt
Reduced Form Eq.
R(t+1)=beta0+beta1*R(t)+beta2*X(1,t)+beta3*X(2,t)+beta4*X(1,t-1)+beta5*X(2,t-1)+beta6*Dummy(t+1)+beta7*Dummy(t)+ν(t+1),
Where beta0=(1-ϕL)*constant;beta1=ϕ;beta2=β1;beta3=β2,beta4=-(ϕ*β1 ),beta5=-(ϕ*β2 ),beta6=θ;beta7=-(ϕ*θ);ν(t+1)=η(t+1)+ (1-ϕL) ε(t+1)
The betas in the reduced form equation can be estimated through nonlinear regression and I would like to estimate my state variable (X3) based on those estimated betas. I know how to estimate nonlinear regression in Rats but I am not sure how to estimate state variable after obtaining the estimated betas. Could you please kindly advise me what I should do here?
Re: a question about state space model with exogenous regres
Posted: Fri Jan 24, 2014 9:45 am
by TomDoan
If you want an estimate of the states, then estimate it as a state space model. Quasi-differencing out the state variable will give you consistent estimates of the parameters. You can try to rebuild the states using your transition equation, but you don't have the information about the pre-sample state. DLM can give you that; NLLS can't.
Re: a question about state space model with exogenous regres
Posted: Mon Jan 27, 2014 3:22 pm
by fan
TomDoan wrote:If you want an estimate of the states, then estimate it as a state space model. Quasi-differencing out the state variable will give you consistent estimates of the parameters. You can try to rebuild the states using your transition equation, but you don't have the information about the pre-sample state. DLM can give you that; NLLS can't.
Dear Tom, thank you for the reply. I see what you mean but I am afraid that I did not make myself clear to you. Actually, I would like to know how I can use those consistent estimates of the parameters from the reduce form equation as the initial values in DLM procedure. Followings are my initial codes and I would like to know how to change the codes to satisfy what I want to do.
linreg evwrd
# constant X1{1} X2{1}
frml(lastreg,vector=b) lineareq evwrd
set du = %resids-%resids{1}
linreg du
# dummy dummy{1}
compute d1=%beta(1)
compute d2=%beta(2)
compute se=sqrt(%seesq)
compute sn=sqrt(0.001*%seesq)
dec frml[symm] sw1 sv1 zf cf
nonlin b a d1 d2=-a*d1 se sn
frml zf = ||d1*dummy+d2*dummy{1}||
frml sw1 = ||sn^2||
frml sv1 = ||se^2||
dlm(presample=ergodic,a=0.2,c=1.0,z=zf,MU=lineareq,f=1.0,sv=sv1,sw=sw1,y=evwrd,method=bfgs,vhat=vhat,svhat=svhat, type=filter)
For now, I can let the initial values for d1, d2, and a to be the correspondent estimates from the reduce form equation. However, I am not sure how to use the correspondent estimates from the reduce from equation as initial values for parameters in vector b and how to assign initial values for se and sn. Could you please kindly advise?
Re: a question about state space model with exogenous regres
Posted: Mon Jan 27, 2014 3:45 pm
by TomDoan
What you're doing in that last post isn't estimating the reduced form model from earlier, though this is probably OK for getting guess values.
Neither the multiple step calculation that you just did nor the non-linear least squares reduced form estimation can separate out the two variances. Instead, they only estimate the variance of the sum. So you need to (somehow) split up the variances to add up the %SEESQ. What you're doing isn't far off from that since you have one taking %SEESQ and the other a small fraction of that.