⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bstrapdemo.html

📁 bootstrp 抽样方法
💻 HTML
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">   <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document.      -->      <title>bstrapdemo</title>      <meta name="generator" content="MATLAB 7.0.4">      <meta name="date" content="2007-04-15">      <meta name="m-file" content="bstrapdemo"><style>body {  background-color: white;  margin:10px;}h1 {  color: #990000;   font-size: x-large;}h2 {  color: #990000;  font-size: medium;}p.footer {  text-align: right;  font-size: xx-small;  font-weight: lighter;  font-style: italic;  color: gray;}pre.codeinput {  margin-left: 30px;}span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.showbuttons {  margin-left: 30px;  border: solid black 2px;  padding: 4px;  background: #EBEFF3;}pre.codeoutput {  color: gray;  font-style: italic;}pre.error {  color: red;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows.  On Gecko-based browsers, the shrink-to-fit doesn't work. */ p,h1,h2,div {  /* for MATLAB's browser */  width: 600px;  /* for Mozilla, but the "width" tag overrides it anyway */  max-width: 600px;  /* for IE */  width:expression(document.body.clientWidth > 620 ? "600px": "auto" );}    </style></head>   <body><pre class="codeinput"><span class="comment">% BSTRAPDEMO  Demonstration of BSTRAP and BSTATS</span><span class="comment">% EXAMPLE   : bstrapdemo (Oh, the FEX code metrics..)</span><span class="comment">% NOTES     : Function HISTF needs to be downloaded from FEX</span><span class="comment">% AUTHOR    : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 4/15/07</span>B = 1000;<span class="comment">% Simple regression</span>n = 100;x = rand(n,1);i = ones(n,1);a = 3;b = 5;y = a + b*x + .5*randn(n,1);<span class="comment">% Bootstrap calculations</span>disp(<span class="string">'A. "fun" with vector output (OLS estimates of regression intercept and slope)'</span>)ls = bstrap(B,1,<span class="string">'olsvector'</span>,[y i x]);disp(<span class="string">'Mean and variance estimates, plus two-sided 95% confidence intervals'</span>)[m,v,cil,ciu] = bstats(ls)        <span class="comment">%#ok  note: may want to exclude actual-sample value</span>disp(<span class="string">'B. "fun" with structure output (OLS estimates of regression intercept and slope)'</span>)ls = bstrap(B,1,<span class="string">'olsstructure'</span>,[y i x]);disp(<span class="string">'Mean and variance estimates, plus two-sided 95% confidence intervals'</span>)[m,v,cil,ciu] = bstats(ls,<span class="string">'b'</span>)    <span class="comment">%#ok  note: may want to exclude actual-sample value</span><span class="comment">% Bootstrap distributions of OLS estimates</span>ab = [ls.b];                      <span class="comment">% note: may want to exclude actual-sample value</span>subplot(3,1,1)scatter(x,y,2)title([<span class="string">'Random sample: \ity = '</span> num2str(a) <span class="string">' + '</span> num2str(b) <span class="string">'x + \epsilon, \rmwhere \itx ~ U\rm[\it0,1\rm]\it,\epsilon ~ N\rm[\it0,1\rm], \iti = 1,..,100'</span>]);subplot(3,1,2)opt.dx   = .01;opt.xmin = a - .5;opt.xmax = a + .5;opt.xmrk = a;histf(ab(1,:),opt)title([<span class="string">'OLS intercept estimate: bootstrap distribution. (True value = \it'</span> num2str(a) <span class="string">'\rm)'</span>])subplot(3,1,3)opt.xmrk = b;opt.xmin = b - .5;opt.xmax = b + .5;histf(ab(2,:),opt)title([<span class="string">'OLS slope estimate: bootstrap distribution. (True value = \it'</span> num2str(b) <span class="string">'\rm)'</span>])</pre><pre class="codeoutput">A. "fun" with vector output (OLS estimates of regression intercept and slope)Mean and variance estimates, plus two-sided 95% confidence intervalsm =    3.1303    4.9428v =    0.0088    0.0222cil =    2.9441    4.6464ciu =    3.3108    5.2397B. "fun" with structure output (OLS estimates of regression intercept and slope)Mean and variance estimates, plus two-sided 95% confidence intervalsm =    3.1394    4.9340v =    0.0085    0.0224cil =    2.9576    4.6374ciu =    3.3256    5.2258</pre><img vspace="5" hspace="5" src="bstrapdemo_01.png"> <p class="footer"><br>         Published with MATLAB&reg; 7.0.4<br></p>      <!--##### SOURCE BEGIN #####% BSTRAPDEMO  Demonstration of BSTRAP and BSTATS
% EXAMPLE   : bstrapdemo (Oh, the FEX code metrics..)  
% NOTES     : Function HISTF needs to be downloaded from FEX
% AUTHOR    : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 4/15/07

B = 1000;

% Simple regression
n = 100;
x = rand(n,1);
i = ones(n,1);
a = 3;
b = 5;
y = a + b*x + .5*randn(n,1);

% Bootstrap calculations
disp('A. "fun" with vector output (OLS estimates of regression intercept and slope)')
ls = bstrap(B,1,'olsvector',[y i x]); 
disp('Mean and variance estimates, plus two-sided 95% confidence intervals')
[m,v,cil,ciu] = bstats(ls)        %#ok  note: may want to exclude actual-sample value 

disp('B. "fun" with structure output (OLS estimates of regression intercept and slope)')
ls = bstrap(B,1,'olsstructure',[y i x]);   
disp('Mean and variance estimates, plus two-sided 95% confidence intervals')
[m,v,cil,ciu] = bstats(ls,'b')    %#ok  note: may want to exclude actual-sample value 

% Bootstrap distributions of OLS estimates
ab = [ls.b];                      % note: may want to exclude actual-sample value 
subplot(3,1,1)
scatter(x,y,2)
title(['Random sample: \ity = ' num2str(a) ' + ' num2str(b) 'x + \epsilon, \rmwhere \itx ~ U\rm[\it0,1\rm]\it,\epsilon ~ N\rm[\it0,1\rm], \iti = 1,..,100']); 

subplot(3,1,2)
opt.dx   = .01;
opt.xmin = a - .5;
opt.xmax = a + .5;
opt.xmrk = a; 
histf(ab(1,:),opt)
title(['OLS intercept estimate: bootstrap distribution. (True value = \it' num2str(a) '\rm)'])

subplot(3,1,3)
opt.xmrk = b;
opt.xmin = b - .5;
opt.xmax = b + .5;
histf(ab(2,:),opt)
title(['OLS slope estimate: bootstrap distribution. (True value = \it' num2str(b) '\rm)'])##### SOURCE END #####-->   </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -