估计状态空间模型的随机参数

此示例显示了如何在状态空间模型中估计状态的随机,自回旋系数。也就是说,此示例使用“ ZIG-ZAG”估计方法对状态空间模型参数估计进行贝叶斯视图。

假设两个国家( X 1 ,,,, t and X 2 ,,,, t 在th)代表两个国家的净出口e end of the year.

  • X 1 ,,,, t is a unit root process with a disturbance variance of σ 1 2

  • X 2 ,,,, t 是一个AR(1)过程,具有未知,随机系数和干扰方差 σ 2 2

  • An observation ( y t )is the exact sum of the two net exports. That is, the net exports of the individual states are unknown.

象征性地,真正的状态空间模型是

X 1 ,,,, t = X 1 ,,,, t - 1 + σ 1 1 ,,,, t X 2 ,,,, t = ϕ X 2 ,,,, t - 1 + σ 2 2 ,,,, t y t = X 1 ,,,, t + X 2 ,,,, t

Simulate Data

从以下方式模拟100年的净出口:

  • 具有差异的平均零高斯噪声系列的单元根过程 0 1 2

  • An AR(1) process with an autoregressive coefficient of 0.6 and a mean zero, Gaussian noise series that has variance 0 2 2

  • X 1 ,,,, 0 = X 2 ,,,, 0 = 0

  • Create an observation series by summing the two net exports per year.

rng(100);% For reproducibilityT = 150; sigma1 = 0.1; sigma2 = 0.2; phi = 0.6; u1 = randn(T,1)*sigma1; x1 = cumsum(u1); Mdl2 = arima('ar',,,,phi,'方差',sigma2^2,'Constant',0);x2 =仿真(mdl2,t,'y0',0);y=X1+X2;数字;plot([x1 x2 y]) legend('x_1',,,,'x_2',,,,'y',,,,'Location',,,,'最好的');ylabel('净出口');Xlabel('时期');

曲折估计方法

Treat ϕ 好像它是未知的和随机的,并使用Zig-Zag方法恢复其分布。实现Zig-Zag方法:

1.选择一个初始值 ϕ 在(-1,1)的间隔中,表示 ϕ z

2。Create the true state-space model, that is, anSSM代表数据生成过程的模型对象。

3. Use the simulation smoother (simsmooth)to draw a random path from the distribution of the second smoothed states. Symbolically, X 2 ,,,, z ,,,, t p (( X 2 ,,,, t | y t ,,,, X 1 ,,,, t ,,,, ϕ = ϕ z

4.创建另一个具有此形式的状态空间模型

ϕ z ,,,, t = ϕ z ,,,, t - 1 X 2 ,,,, z ,,,, t = X 2 ,,,, z ,,,, t - 1 ϕ z ,,,, t + 0 8 2 ,,,, t

In words, ϕ z ,,,, t 是静态状态和 X 2 ,,,, z ,,,, t is an "observed" series with time varying coefficient C t = X 2 ,,,, z ,,,, t - 1

5.使用模拟更顺畅地从平滑的分布中绘制随机路径 ϕ z ,,,, t 系列。象征性地 ϕ z ,,,, t p (( ϕ | X 2 ,,,, z ,,,, t ,,,,where X 2 ,,,, z ,,,, t 涵盖了真实状态空间模型和观测值的结构。 ϕ z ,,,, t 是静态的,因此您可以保留一个值( ϕ z )。

6.重复步骤2-5多次并存储 ϕ z each iteration.

7. Perform diagnostic checks on the simulation series. That is, construct:

  • Trace plots to determine the burn in period and whether the Markov chain is mixing well.

  • 自相关图确定需要删除多少平局才能获得混合良好的马尔可夫链。

8.其余系列表示从后部分布中得出的 ϕ 。You can compute descriptive statistics, or plot a histogram to determine the qualities of the distribution.

使用Zig-Zag方法估算随机系数

Specify initial values, preallocate, and create the true state-space model.

phi0 = -0.3;PHI初始值的%z = 1000;% Number of times to iterate the zig-zag methodphiz = [phi0;Nan(Z,1)];% Preallocatea = [1 0;0 nan];b = [sigma1;sigma2];C = [1 1];mdl = ssm(a,b,c,'statepe',,,,[2; 0]);

MDL是一个SSM模型对象。这充当占位符 ϕ

曲折方法的迭代步骤2-5。

为了j = 2 :( z + 1);% Draw a random path from smoothed x_2 series.Xz=simsmooth(Mdl,y,“参数”,,,,phiz(j-1));% The second column of xz is a draw from the posterior distribution of x_2.% Create the intermediate state-space model.az = 1;bz = 0;cz = num2cell(xz((1:(end -end -1)),2));dz = sigma2;mdlz = SSM(AZ,BZ,CZ,DZ,'statepe',2);%从平滑的PHIZ系列中绘制一个随机路径。phizvec = simsmooth(Mdlz,xz(2:end,2)); phiz(j) = phizvec(1);%phiz(j)是从PHI的后验分布中抽取的结尾

phiz是马尔可夫链。在分析后验分布之前 ϕ ,,,,you should assess whether to impose a burn-in period, or the severity of the autocorrelation in the chain.

Determine Quality of Simulation

Draw a trace plot for the first 100, 500, and all of the random draws.

vec = [100 500 Z]; figure;为了j = 1:3;子图(3,1,j)图(phiz(1:vec(j)));标题('Trace Plot for \phi');Xlabel(“仿真号码”);轴tight;结尾

According to the first plot, transient effects die down after about 20 draws. Therefore, a short burn-in period should suffice. The plot of the entire simulation shows that the series settles around a center.

删除前20个绘制后,绘制该系列的自相关函数。

倦怠= 21:z;数字;Autocorr(Phiz(倦怠));

这autocorrelation function dies out rather quickly. It doesn't seem like autocorrelation in the chain is an issue.

确定后部分布的质量 ϕ 通过计算模拟统计数据并绘制简化的随机抽奖集的直方图。

xbar =平均值(phiz(倦怠))
XBAR = 0.5104
XSTD = STD(PHIZ(倦怠))
Xstd = 0.0988
ci = norminv([0.025,0.975],xbar,xstd);% 95% confidence interval数字;histogram(phiz(burnOut),'Normalization',,,,'PDF');H = GCA;抓住on;simx = linspace(H.Xlim(1),H.Xlim(2),100);simpdf = normpdf(simx,xbar,xstd);情节(Simx,Simpdf,'k',,,,'LineWidth',2);h1 = plot([xbar xbar],h.YLim,'r',,,,'LineWidth',2);h2 =图([0.6 0.6],h.ylim,,'g',,,,'LineWidth',2);H3 =图([CI(1)CI(1)],H.Ylim,,' -  r',,,,...[CI(2)CI(2)],H.ylim,,' -  r',,,,'LineWidth',2);图例([H1 H2 H3(1)],{'Simulation Mean',,,,“真正的卑鄙”,,,,'95% CI'}); h.XTick = sort([h.XTick xbar]); h.XTickLabel{h.XTick == xbar} = xbar; h.XTickLabelRotation = 90;

Method: Maximum likelihood (fminunc) Sample size: 150 Logarithmic likelihood: -10.1434 Akaike info criterion: 22.2868 Bayesian info criterion: 25.2974 | Coeff Std Err t Stat Prob ------------------------------------------------------- c(1) | 0.53590 0.19183 2.79360 0.00521 | | Final State Std Dev t Stat Prob x(1) | -0.85059 0.00000 -6.45811e+08 0 x(2) | 0.00454 0 Inf 0

后分布 ϕ 大约正常,平均值和标准偏差约为0.51和0.1。真实的卑鄙 ϕ 为0.6,它小于模拟平均值右侧的一个标准偏差。

计算最大似然估计 ϕ 。也就是说 ϕ 作为固定但未知参数,然后估算Mdl使用卡尔曼过滤器和最大似然。

[〜,estparams] =估计(MDL,Y,PHI0)
estParams = 0.5359

Mle的 ϕ 为0.54。这两个估计都在一个标准偏差或标准误差范围内 ϕ

也可以看看

||||

相关示例

更多关于