matlab回归分析bootstrap误差估计
(2017-07-14 09:52:09)
标签:
bootstrap误差估计回归分析 |
分类: 数学算法 |
%bootstrap方法使用实例
17/07/13 潘海东(OUC)
x=rand(10,1);
x=[ones(10,1),x];
y=x*[2;0.5]+0.1*rand(10,1); %添加误差
[b,bint1]=regress(y,x,0.95); %bint1为估计参数b的95%置信区间
yfit=x*b;
resid=y-yfit;
se=std(bootstrp(1000,@(bootr)regress(yfit+bootr,x),resid)); %bootstrap方法抽样1000次
bint2(1,1)=b(1)-1.96*se(1)/sqrt(1000); %bint2为估计参数b的95%置信区间
bint2(1,2)=b(1)+1.96*se(1)/sqrt(1000);
%假设参数分布服从t分布,0.95对应1.96
bint2(2,1)=b(2)-1.96*se(2)/sqrt(1000);
bint2(2,2)=b(2)+1.96*se(2)/sqrt(1000);
%给定参数为2
0.5,最小二乘求得为2.0192
0.5461
%多元回归给出的95%置信区间为[2.0178 2.0205] [0.5442 0.5481]
%bootstrap方法给出的95%区间[2.0180 2.0203] [0.5444 0.5478]
17/07/13 潘海东(OUC)
x=rand(10,1);
x=[ones(10,1),x];
y=x*[2;0.5]+0.1*rand(10,1); %添加误差
[b,bint1]=regress(y,x,0.95); %bint1为估计参数b的95%置信区间
yfit=x*b;
resid=y-yfit;
se=std(bootstrp(1000,@(bootr)regress(yfit+bootr,x),resid)); %bootstrap方法抽样1000次
bint2(1,1)=b(1)-1.96*se(1)/sqrt(1000); %bint2为估计参数b的95%置信区间
bint2(1,2)=b(1)+1.96*se(1)/sqrt(1000);
bint2(2,1)=b(2)-1.96*se(2)/sqrt(1000);
bint2(2,2)=b(2)+1.96*se(2)/sqrt(1000);
%给定参数为2
%多元回归给出的95%置信区间为[2.0178 2.0205] [0.5442 0.5481]
%bootstrap方法给出的95%区间[2.0180 2.0203] [0.5444 0.5478]
前一篇:使用matlab抓取网络数据