Page 1 of 1

%XX

Posted: Thu Apr 05, 2012 4:29 am
by chiade
Dear Sir,

I had managed to define the drifting coefficients, as I had asked in my previous post. I had a new question, so I just started a new topic. Apologies if I had started too many topics. I set up the below, as indicated in my previous post. My question is how do I derive the %xx for my coefficients? There are a total of 11 coefficients as seen from results below.

In my ceqn and ceqn1 equations, there are 2 fixed coefficients each using the command mu i.e. break 1, 2,3 and 4. The %xx derived from DLM formula includes variances of lsigsqv and lsigsqw, which are the variances themselves. So, it is incorrect to use the %xx values. I thought of using the vstates as variances, which I think should be the right one but I do not know how to derive %xx values for the covariance between the drifting and fixed coefficients.

How are the covariances in %xx derived? I had been trying to derive them for sometime but to no avail. I understand that the variances i.e. diagonal elements are the squares of standard errors. Also, the RATS user manual indicated that (X' X)−1 as well as sigma^2*(X' X)−1. which is the correct one to use as i understand the latter is for scaling.

I would like to clarify the difference between vstates and swhat=wHswhat as these figures are different.

I had tried to derive %xx values in a VAR model i.e. model with HH and WTIC using 1 lag but failed, There are 2 similar regressors in each equation. My concern is how to combine the 2 equations into a 2x2 %xx matrix since there are also similar regressors in both my equations (ceqn and ceqn1). I can't seem to find any solution to these, which would allow me to derive the %xx for my DLM model.

Hope that you could kindly guide me and clarify my doubts. Many thanks.

Code: Select all

=============================================
linreg(define=ceqn,noprint) wtic 1997:11:28 2011:6:24  
#  trend1 wtic{1}

linreg(define=ceqn1,noprint) hh 1997:11:28 2011:6:24  
# trend1 hh{1}

dec vect[series] b(4)  lower(4) upper(4) ts(4) vs(4) whv(2)
dec vect lsigsqw(4)
dec symm lsigsqv(2,2)
dec rect[ser] whsv(4,2)  whsw(4,4)   

nonlin lsigsqv lsigsqw break1 break2 break3 break4

compute lsigsqw=%log(||.0001,.0001,.0001,.0001||)
compute lsigsqv=%log(||.0001,.0001|.0001,.0001||)

compute break1=break2=.1, break3=break4=break5=break6=break7=break8=break9=.1

dlm(mu=||break1+BREAK2*HH{1},break3+BREAK4*wtic{1}||,c=%eqnxvector(ceqn,t)~\%eqnxvector(ceqn1,t),sw=%diag(%exp(lsigsqw)),sv=%exp(lsigsqv),presample=ergodic,y=||wtic,hh||,$
  method=bfgs,iters=500,type=smooth,vhat=wHvhat,swhat=wHswhat,svhat=wHsvhat,yhat=wHyhat) 1997:11:28 2011:6:24 $ xstates vstates


=================================================





DLM - Estimation by BFGS
Convergence in    53 Iterations. Final criterion was  0.0000003 <=  0.0000100
Weekly Data From 1997:11:28 To 2011:06:24
Usable Observations                       709
Rank of Observables                      1414
Log Likelihood                      -813.1364

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  LSIGSQV(1,1)                  -4.36944872   0.24402764    -17.90555  0.00000000
2.  LSIGSQV(2,1)                  -5.59570686   0.54673897    -10.23470  0.00000000
3.  LSIGSQV(2,2)                  -5.43510740   0.74849166     -7.26141  0.00000000
4.  LSIGSQW(1)                   -14.19777774   0.17103291    -83.01196  0.00000000
5.  LSIGSQW(2)                    -6.85280373   0.22323802    -30.69730  0.00000000
6.  LSIGSQW(3)                   -15.44172007   0.27018690    -57.15199  0.00000000
7.  LSIGSQW(4)                    -4.80792450   0.08560003    -56.16732  0.00000000
8.  BREAK1                         1.76220698   0.44688346      3.94333  0.00008036
9.  BREAK2                         0.07439930   0.02657603      2.79949  0.00511836
10. BREAK3                         1.59566462   0.38569948      4.13707  0.00003518
11. BREAK4                         0.09031646   0.04115256      2.19467  0.02818699
================================================================

Re: %XX

Posted: Thu Apr 05, 2012 10:50 am
by TomDoan
Read section 4.5 in the RATS v8 User's Guide. %XX is the estimate of the inverse Hessian of the log likelihood. You can't "derive" it. BFGS, in particular, arrives at the %XX by an iterative updating process, so it will be slightly different with different initial values even if the coefficients themselves are converged to a much higher precision. Note that BFGS standard errors are routinely used in the literature.

Re: %XX

Posted: Fri Apr 06, 2012 6:17 am
by chiade
Dear Sir,

If i am to use vstates i.e. variances of the states, and expand my model to become a 8x2 matrix and subequently use them as %xx in the calculation of monte carlo draw for IRF, will it cause any problems? I turned it into a 8x2 matrix as 6 out of 8 of the cofficients are drifting, is it possible to turn it into a 4x2 matrix, considering that this is is a DLM model rather than a constant VAR model? or there's no harm in expanding the matrix apart from a loss of DOF i.e. %nreg = 8 rather than = 4?

Can I carify that vstates = sigma^2 (x'x)^-1? I am confused over the definition of covariance matrix of coefficients on page 67 of the user's guide.

(I used %modelsetcoeffs to set coefficients i.e. for www: constant = 1.76; trend 1 = xstates(t)(1); wtic{1} = xstates(t)(2); hh{1} = 0.09; constant =0.0; trend1=0.00, wtic{1}=0.0; hh{1}=0.0)

I set up the below using example from this forum and the user's guide and wonder whether i had done it correctly? Many thanks for your help in clarifying many of my doubts. Hopefully, I can improve my RATS skills (which is still low) and recommend this software to my school and potential students.
================================================

Code: Select all

equation www wtic
# constant trend1 wtic{1}   hh{1} constant trend1 wtic{1}   hh{1}
equation hhh hh
#  constant trend1 wtic{1}  hh{1} constant trend1 wtic{1}   hh{1}
group fuel www  hhh

compute nstep=16			;*Number of response steps
compute ndraws=10000		;*Number of keeper draws
compute %nreg= 8

compute nvar   =2
compute fxx    =%decomp(%xx)
compute fwish  =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=xx
*
*
declare vect[rect] %%responses(ndraws)
declare rect[series] impulses1(nvar,nvar)
*
infobox(action=define,progress,lower=1,upper=ndraws) "Monte Carlo Integration"
do draw=1,ndraws
   if %clock(draw,2)==1 {
      compute sigmad  =%ranwisharti(fwish,wishdof)
      compute fsigma  =%bqfactor(%sigma,%modellagsums(fuel))
      compute betau   =%ranmvkron(fsigma,fxx)
      compute betadraw=betaols+betau
   }
   else
      compute betadraw=betaols-betau
   *

   * Push the draw for the coefficient back into the model.

   compute %modelsetcoeffs(fuel,betadraw)
   *
   * Compute the BQ factor using the recalculated lag sums of the model
	*
	compute factor=%bqfactor(sigmad,%modellagsums(fuel))
   impulse(print,model=fuel,factor=factor,results=impulses1,steps=nstep)
   errors(print,model=fuel,factor=factor,results=errors1,steps=nstep)
	*
   * Save the impulse responses
	*
   dim %%responses(draw)(nvar*nvar,nstep)
   ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses1,j)),ix(i)
   infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=fuel)

Re: %XX

Posted: Fri Apr 06, 2012 10:15 am
by TomDoan
What do you think you are "integrating" over in the MC integration? If you want to take the final estimates of the mean and covariance matrix for the drifting coefficients, those are estimated by DLM as the mean and variance (3rd and 4th parameters)---they have nothing to do with the %XX. If you want to take into account that the mean and variance of the coefficients aren't known (since they depend upon estimated parameters), then you're getting into a very complicated sampling process which would require doing Metropolis-Hastings on the estimated parameters and re-running the Kalman filter for each proposal for the parameters.

Re: %XX

Posted: Wed Apr 11, 2012 10:43 pm
by chiade
Hi Sir,

In my case, I had fixed coefficients with the usage of mu command in DLM as well as drifitng coefficients (xstates).

linreg(define=ceqn,noprint) wtic 1997:11:28 2011:6:24 a1
# trend1 WTIC{4} bsbc{1}

linreg(define=ceqn1,noprint) BSBC 1997:11:28 2011:6:24 a1
# wtic{1 2 3 4}

dlm(mu=||break1+BREAK2*WTIC{3},break3*TREND1+break4*bsbc{1}+break5*bsbc{4}||,c=%eqnxvector(ceqn,t)~\%eqnxvector(ceqn1,t),sw=%diag(%exp(lsigsqw)),sv=%exp(lsigsqv),presample=ergodic,y=||wtic,bsbc||,$
method=bfgs,iters=500,type=smooth,vhat=wbvhat,svhat=wbsvhat,yhat=wbyhat) 1997:11:28 2011:6:24 xstates vstates


How do I get the covariance between the fixed and drifitng coefficients which I need for the below? variances and covariances for the drifting coefficients were vstates (vs). if i want to find the pooled variances for sum of 4 drifitng coefficients, do i use the formula:
sqrtpoolvarbsbwti = sqrt(vs(4,4)+vs(5,5)+vs(6,6)+vs(7,7)+2*vs(4,5)+2*vs(4,6)+2*vs(4,7)+2*vs(5,6)+2*vs(5,7)+2*vs(6,7))

or with weights from the drifting coefficients:

sqrtpoolvarbsbwti = sqrt(b(4)^2*vs(4,4)+b(5)^2*vs(5,5)+b(6)^2*vs(6,6)+b(7)^2*vs(7,7)+2*b(4)*b(5)*vs(4,5)+2*b(4)*b(6)*vs(4,6)+2*b(4)*b(7)*vs(4,7)+2*b(5)*b(6)*vs(5,6)+2*b(5)*b(7)*vs(5,7)+2*b(6)*b(7)*vs(6,7))

I was thinking that it should be summed w/o weights since these are for the t-statistics of the drifitng coefficients.

Hope to get some clarification. Many thanks.

Re: %XX

Posted: Thu Apr 12, 2012 6:54 am
by TomDoan
The variances for the fixed coefficients are due to sampling error---the variances for the drifting ones are due to their being unobservable even if the model is known exactly. You can't compute the covariance between the two using any simple formula. You have to do a very complicated sampling process which would require doing Metropolis-Hastings on the estimated parameters and re-running the Kalman filter for each proposal for the parameters. See the errorbands.rpf program on http://www.estima.com/forum/viewtopic.php?f=28&t=432 as an example of something similar.