📄 the matlab statistics package bootstrap.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0066)http://www-stat.stanford.edu/~susan/courses/b494/index/node77.html -->
<!--Converted with LaTeX2HTML 2K.1beta (1.57)original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>The matlab statistics package bootstrap</TITLE>
<META content="The matlab statistics package bootstrap" name=description>
<META content=t name=keywords>
<META content=document name=resource-type>
<META content=global name=distribution>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2523" name=GENERATOR>
<META http-equiv=Content-Style-Type content=text/css><LINK
href="The matlab statistics package bootstrap.files/t.css" rel=STYLESHEET><LINK
href="node78.html" rel=next><LINK href="node74.html" rel=previous><LINK
href="node50.html" rel=up><LINK href="node78.html" rel=next></HEAD>
<BODY><!--Navigation Panel--><A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node78.html"
name=tex2html1191><IMG height=24 alt=next
src="The matlab statistics package bootstrap.files/next.png" width=37
align=bottom border=0></A> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node50.html"
name=tex2html1187><IMG height=24 alt=up
src="The matlab statistics package bootstrap.files/up.png" width=26 align=bottom
border=0></A> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node76.html"
name=tex2html1181><IMG height=24 alt=previous
src="The matlab statistics package bootstrap.files/prev.png" width=63
align=bottom border=0></A> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node124.html"
name=tex2html1189><IMG height=24 alt=index
src="The matlab statistics package bootstrap.files/index.png" width=43
align=bottom border=0></A> <BR><B>Next:</B> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node78.html"
name=tex2html1192>Bootstrapping Regression</A> <B>Up:</B> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node50.html"
name=tex2html1188>The Bootstrap, Permutation Tests,</A> <B>Previous:</B> <A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node76.html"
name=tex2html1182>The Hardy Weinberg Example</A> <B><A
href="http://www-stat.stanford.edu/~susan/courses/b494/index/node124.html"
name=tex2html1190>Index</A></B> <BR><BR><!--End of Navigation Panel-->
<H1><A name=SECTION00360000000000000000>The matlab statistics package
bootstrap</A> </H1>Preliminaries : The matlab function <TT>eval</TT> :
<PRE>
EVAL Execute string with MATLAB expression.
EVAL(s), where s is a string, causes MATLAB to execute
the string as an expression or statement.
EVAL(s1,s2) provides the ability to catch errors. It
executes string s1 and returns if the operation was
successful. If the operation generates an error,
string s2 is evaluated before returning. Think of this
as EVAL('try','catch'). The error string produced by the
failed 'try' can be obtained with LASTERR.
[X,Y,Z,...] = EVAL(s) returns output arguments from the
expression in string s.
The input strings to EVAL are often created by
concatenating substrings and variables inside square
brackets. For example:
Generate a sequence of matrices named M1 through M12:
for n = 1:12
eval(['M' num2str(n) ' = magic(n)'])
end
Run a selected M-file script. The strings making up
the rows of matrix D must all have the same length.
D = ['odedemo '
'quaddemo'
'fitdemo '];
n = input('Select a demo number: ');
eval(D(n,:))
See also FEVAL, EVALIN, ASSIGNIN, LASTERR.
</PRE>
<P>
<P><PRE>%BOOTSTRP Bootstrap statistics.
% BOOTSTRP(NBOOT,BOOTFUN,D1,...) draws NBOOT bootstrap data samples and
% analyzes them using the function, BOOTFUN. NBOOT must be a
% positive integer.
% BOOTSTRAP passes the (data) D1, D2, etc. to BOOTFUN.
%
% [BOOTSTAT,BOOTSAM] = BOOTSTRP(...) Each row of BOOTSTAT contains
% the results of BOOTFUN on one bootstrap sample. If BOOTFUN returns a matrix
% then this output is converted to a long vector for storage in BOOTSTAT.
% BOOTSAM is a matrix of indices into the row
% Initialize matrix to identify scalar arguments to bootfun.
scalard = zeros(nargin-2,1);
lp = '('; % Left parenthesis string variable.
rp = ')'; % Right parenthesis string variable.
c = ','; % Comma string variable.
ds = 'd'; % 'd' as a string variable.
% Construct argument list for bootfun
for k = 3:nargin
dk = [ds,num2str(k-2)];
[row,col] = size(eval(dk));
if max(row,col) == 1
scalard(k-2) = 1;
end
if row == 1 & scalard(k-2) == 0
eval([dk,'=',dk,'(:);']);
row = col;
end
if k == 3
pstring = [lp,dk];
n = row;
if nargin == 3
pstring = [pstring,rp];
end
elseif k == nargin & nargin > 3
pstring = [pstring,c,dk,rp];
else
pstring = [pstring,c,dk];
end
end
% Create index matrix of bootstrap samples.
bootsam = unidrnd(n,n,nboot);
% Get result of bootfun on actual data and find its size.
thetafit = eval([bootfun,pstring]);
[ntheta ptheta] = size(thetafit);
% Initialize a matrix to contain the results of all the
%bootstrap calculations.
bootstat = zeros(nboot,ntheta*ptheta);
dbs = 'db';
% Do bootfun - nboot times.
for bootiter = 1:nboot
for k = 3:nargin
dk = [ds,num2str(k-2)];
dbk = [dbs,num2str(k-2)];
if scalard(k-2) == 0
eval([dbk,'=',dk,'(bootsam(:,',num2str(bootiter),'),:);']);
else
eval([dbk,'=',dk,';']);
end
if k == 3
pstring = [lp,dbk];
n = row;
if nargin == 3
pstring = [pstring,rp];
end
elseif k == nargin & nargin > 3
pstring = [pstring,c,dbk,rp];
else
pstring = [pstring,c,dbk];
end
end
evalstr = [bootfun,pstring];
tmp = eval(evalstr);
bootstat(bootiter,:) = (tmp(:))';
end
</PRE>
<P><BR>
<HR>
<ADDRESS>Susan Holmes 2002-01-12 </ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -