* * Chapter 8 - Norway data * open data norwayfinland.txt calendar(a) 1970 data(format=free,org=columns,skips=1) 1970:01 2003:01 year norway finland * set lognorway = log(norway) * @LocalDLMInit(irreg=sigsqeps) lognorway nonlin sigsqeps sigsqxi compute sigsqxi=sigsqeps*.01 * * For comparison, we need both filtered and smoothed estimates * dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=lognorway,$ method=bfgs,vhat=vhat,svhat=svhat) / fstates dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=lognorway,$ type=smooth) / sstates * * The graph doesn't quite match because of a different definition of * "filtered" state. For the RATS DLM instruction, the filtered state is * the expectation of X(t) given information through t. In the text, the * filtered state is the expectation of X(t) given information through * t-1. "Smoothed" means the same regardless. * set filtered = %scalar(fstates) set smoothed = %scalar(sstates) graph(footer="Smoothed and filtered state of the local level model",$ key=upright,klabels=||"smoothed level","filtered level"||) 2 # smoothed # filtered * set perror = %scalar(vhat) set pevar = %scalar(svhat) * * The prediction error and prediction error variance really only make * sense for entries 2 and above (or, in general, beyond the number of * unit roots in the state-space model). * spgraph(vfields=2,samesize,$ footer="Figure 8.7 One-step ahead prediction errors and their variances") graph(key=upleft,klabels=||"prediction errors"||) # perror 2 * graph(key=upright,klabels=||"prediction error variance"||) # pevar 2 * spgraph(done)