From: Nathan Jensen on
My question concerns the output of the bootstrp function.

The bootstrap function is as follows:
BOOTSTAT = BOOTSTRP(NBOOT,BOOTFUN,D1,...)

If BOOTFUN has more than one output (i.e. [P,S] = POLYFIT(X,Y,N)) how to do I get BOOTSTAT to display all of the outputs (i.e. BOOTSTAT = [P,S])?

Thanks,

Nate
From: Peter Perkins on
On 7/30/2010 9:59 AM, Nathan Jensen wrote:
> My question concerns the output of the bootstrp function.
>
> The bootstrap function is as follows:
> BOOTSTAT = BOOTSTRP(NBOOT,BOOTFUN,D1,...)
>
> If BOOTFUN has more than one output (i.e. [P,S] = POLYFIT(X,Y,N)) how to
> do I get BOOTSTAT to display all of the outputs (i.e. BOOTSTAT = [P,S])?

Nathan, you can use the example of bootstrapping mean and std as a
starting point, i.e., you'll have to write a function that returns a row
vector. However, the second output of POLYFIT is a structure, so your
function will need to put p and s into a 1x2 cell array. In addition,
the standard way to bootstrap a regression is on the residuals. You may
decide to do otherwise, but you could start there.

Here's what I would do. This is somewhat of an advanced maneuver,
because of that structure that polyfit spits out. Be much simpler if
all you wanted was to bootstrap p. One might observe that bootstrapping
a regression is often to get estimates of precision, and that the S
structure has quantities that are themselves used for estimates of
precision, so why do you want to bootstrap S?

function tmp
x = randn(10,1);
y = randn(10,1);
[p,s] = polyfit(x,y,1)

yfit = polyval(p,x,s);
resid = y - yfit;

function c = bootfun(bootresid)
[p,s] = polyfit(x,yfit+bootresid,1);
c = {p s};
end

bootsamps = bootstrp(5, @bootfun, resid)

end


Hope this helps.
From: Richard Willey on
As a quick follow-up, the code that Peter provided is an example of a
nonparametric residual bootstrap.

Here is a slightly modified version that uses a parametric residual
bootstrap. The key distinction:

The parametric residual bootstrap creates a model that describes the
residuals and draws samples from this distribution.

The nonparametric residual bootstrap draws samples (with replacement) from
the original residual vector.



function tmp

x = randn(10,1);

y = randn(10,1);

[p,s] = polyfit(x,y,1)



yfit = polyval(p,x,s);

resid = y - yfit;



foo = fitdist(resid, 'normal');

new_resid = random(foo, length(resid),1);



function c = bootfun(bootresid)

[p,s] = polyfit(x,yfit+bootresid,1);

c = {p s};

end



bootsamps = bootstrp(5, @bootfun, new_resid)



end