* * Chapter 2. UK data. * open data ukdriversksi.txt calendar(m) 1969 data(format=free,org=columns,skips=1) 1969:01 1984:12 ksi set logksi = log(ksi) * * This *can* be done using linreg logksi;# constant. This shows how to * estimate the model using DLM. There are two variance parameters (for * the measurement error and the change in the local level), but we peg * the second to 0. The EXACT option takes care of the unknown level. The * value for this is the *final* state when you Kalman filter. * compute sigsqeps=.0001 nonlin sigsqeps sigsqxi=0.0 dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=logksi,$ method=bfgs,vhat=vhat,svhat=svhat) / xstates * set kflevel = %scalar(xstates) graph(footer="Sequential estimates of overall process mean") # kflevel * disp "Overall mean" kflevel(%regend()) * set level = kflevel(%regend()) graph(footer="Figure 2.1 Deterministic level",$ key=upright,klabels=||"Log UK drivers KSI","Deterministic Level"||) 2 # logksi # level set irreg = logksi-level graph(footer="Figure 2.2 Irregular Component for Deterministic Level") # irreg * set resids = %scalar(vhat)/sqrt(%scalar(svhat)) @STAMPDiags(ncorrs=15) resids * * Same model, but freeing up the variance on the drift in the level. * Estimate and do the diagnostics using the Kalman filter. * nonlin sigsqeps sigsqxi dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=logksi,$ method=bfgs,vhat=vhat,svhat=svhat) / xstates set resids = %scalar(vhat)/sqrt(%scalar(svhat)) @STAMPDiags(ncorrs=15) resids * * Compute estimated components using Kalman smoothing * dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=logksi,$ type=smooth) / xstates set level = %scalar(xstates(t)) set irreg = logksi-level graph(footer="2.3 Stochastic Level",$ key=upright,klabels=||"Log UK Drivers KSI","Stochastic Level"||) 2 # logksi # level graph(footer="2.4 Irregular component for local level model") # irreg