Thread Subject: bootstrap

Subject: bootstrap

From: Rogelio

Date: 16 Oct, 2009 20:53:02

Message: 1 of 6

Hi,

Is it possible to obtain bootstraped samples for two different functions written in the same M.file?? My M.file contains two functions that I want to bootstrap, so it looks like this: function [rho f]=micorr(data)......

Then if I call the bootstr function as [bootstat bootsam]=bootstr(999,@micorr,data), I just obtain the statistic rho and not both rho and f. To get the bootstraped samples for the second statistic I need to delete rho from my M.file.

How can get both at once???

Thank you!

Subject: bootstrap

From: Peter Perkins

Date: 19 Oct, 2009 11:01:58

Message: 2 of 6

Rogelio wrote:
> Hi,
>
> Is it possible to obtain bootstraped samples for two different functions written in the same M.file?? My M.file contains two functions that I want to bootstrap, so it looks like this: function [rho f]=micorr(data)......
>
> Then if I call the bootstr function as [bootstat bootsam]=bootstr(999,@micorr,data), I just obtain the statistic rho and not both rho and f. To get the bootstraped samples for the second statistic I need to delete rho from my M.file.
>
> How can get both at once???

See the documentation. The second example in the M help, or the third in the HTML reference page.

Subject: bootstrap

From: Tom Lane

Date: 19 Oct, 2009 22:06:31

Message: 3 of 6

> Is it possible to obtain bootstraped samples for two different functions
> written in the same M.file?? My M.file contains two functions that I want
> to bootstrap, so it looks like this: function [rho f]=micorr(data)......
>
> Then if I call the bootstr function as [bootstat
> bootsam]=bootstr(999,@micorr,data), I just obtain the statistic rho and
> not both rho and f. To get the bootstraped samples for the second
> statistic I need to delete rho from my M.file.

Rogelio, Peter pointed you to information about bootstrapping statistics
that are not scalar-valued.

If you're having trouble figuring out how to get rho and f into a single
output, you can modify your function to compute

   both = [rho f];

and make "both" the return value from the function.

If you can't easily modify the function, you could use something
intermediate to call the function and return the values as a single vector.
Here's an example where I did that to combine the mu and sigma values that
the normfit function returns, without modifying the normfit function itself.

>> x = randn(20,1);
>> [mu,sig] = normfit(x)
mu =
    0.6646
sig =
    1.4797
>> type getmusig
function musig = getmusig(x)
[mu,sig] = normfit(x);
musig = [mu,sig];
>> musig = getmusig(x)
musig =
    0.6646 1.4797

-- Tom

Subject: bootstrap

From: Rogelio

Date: 20 Oct, 2009 12:27:03

Message: 4 of 6

"Tom Lane" <tlane@mathworks.com> wrote in message <hbint8$q2c$1@fred.mathworks.com>...
> > Is it possible to obtain bootstraped samples for two different functions
> > written in the same M.file?? My M.file contains two functions that I want
> > to bootstrap, so it looks like this: function [rho f]=micorr(data)......
> >
> > Then if I call the bootstr function as [bootstat
> > bootsam]=bootstr(999,@micorr,data), I just obtain the statistic rho and
> > not both rho and f. To get the bootstraped samples for the second
> > statistic I need to delete rho from my M.file.
>
> Rogelio, Peter pointed you to information about bootstrapping statistics
> that are not scalar-valued.
>
> If you're having trouble figuring out how to get rho and f into a single
> output, you can modify your function to compute
>
> both = [rho f];
>
> and make "both" the return value from the function.
>
> If you can't easily modify the function, you could use something
> intermediate to call the function and return the values as a single vector.
> Here's an example where I did that to combine the mu and sigma values that
> the normfit function returns, without modifying the normfit function itself.
>
> >> x = randn(20,1);
> >> [mu,sig] = normfit(x)
> mu =
> 0.6646
> sig =
> 1.4797
> >> type getmusig
> function musig = getmusig(x)
> [mu,sig] = normfit(x);
> musig = [mu,sig];
> >> musig = getmusig(x)
> musig =
> 0.6646 1.4797
>
> -- Tom
>

Thanks Tom! pretty stright forward solution!
Are you familiar with bootstrapping?? I have a question.....

I am bootstrapping the correlation coefficient, rhoboot, between 2 vectors of size n x 1 and also an estimation of its variance,varboot, (im not using the sample variance).

Given that I could not bootstrap both statistics at once, I did it separatelly. If I compare the results from bootstrapping both statistics at once with the results obtataind with separate bootstraping procedure, they differ in some sence.

Even thoug the bootstraped statistics have the same quantiles and mean under both schemes, plotting rhoboot vs varboot is different. When I do the plot for the bootstrap procedure including both statistic at once, it is a clear dependence between the correlation and its variance. But, when I bootstrap the statistic separately and I do the plot, the dependece is not present in the graph.

Any idea what is going on??

Subject: bootstrap

From: Richard Willey

Date: 20 Oct, 2009 18:27:48

Message: 5 of 6

> Are you familiar with bootstrapping?? I have a question.....
>
> I am bootstrapping the correlation coefficient, rhoboot, between 2 vectors
> of size n x 1 and also an estimation of its variance,varboot, (im not
> using the sample variance).
>
> Given that I could not bootstrap both statistics at once, I did it
> separatelly. If I compare the results from bootstrapping both statistics
> at once with the results obtataind with separate bootstraping procedure,
> they differ in some sence.
>
> Even thoug the bootstraped statistics have the same quantiles and mean
> under both schemes, plotting rhoboot vs varboot is different. When I do
> the plot for the bootstrap procedure including both statistic at once, it
> is a clear dependence between the correlation and its variance. But, when
> I bootstrap the statistic separately and I do the plot, the dependece is
> not present in the graph.
>
> Any idea what is going on??

Hi Rogelio

Without seeing your code, its hard to know exactly whats happening, however,
I'm willing to make a guess:

Any time you're performing a bootstrap, you're drawing random samples with
replacement. This process is intrinsically random, so its natural to expect
small amounts of variance from one bootstrap to another. In this case,
however, it doesn't sound like you're dealing with a little imprecision;
rather, your results are changing dramatically. This in turn suggests the
following:

When you're bootstrapping your two statistics separately, you're drawing
your samples in a different order.
Its entirely possible that this discrepancy in the ordering is eliminating
the correlation between the two data series.

There are a few different ways that you can control for this. You can play
games with the seed of the random number generator. Alternatively, you can
create an index and use this to preserve the sampling order across
variables. (I'm sure folks can suggest any number of better solutions)

I will make one (general) suggestion.

Conceptually, bootstraps are quite simple. However, there are a lot of
different ways that you can shoot yourself in the foot. I often find that
the easiest way to avoid trouble is to make things as simple as possible.
Start out by implementing your own bootstrap using the randsample option
(also contained inside Statistics Toolbox). Once you've done this a few
times and have a really good understanding how you're applying this
technique THEN move over to functions like bootstrp and bootci...

regards,

Richard

Subject: bootstrap

From: Rogelio

Date: 20 Oct, 2009 21:42:00

Message: 6 of 6

"Richard Willey" <rwilley@mathworks.com> wrote in message <hbkvf4$c91$1@fred.mathworks.com>...
> > Are you familiar with bootstrapping?? I have a question.....
> >
> > I am bootstrapping the correlation coefficient, rhoboot, between 2 vectors
> > of size n x 1 and also an estimation of its variance,varboot, (im not
> > using the sample variance).
> >
> > Given that I could not bootstrap both statistics at once, I did it
> > separatelly. If I compare the results from bootstrapping both statistics
> > at once with the results obtataind with separate bootstraping procedure,
> > they differ in some sence.
> >
> > Even thoug the bootstraped statistics have the same quantiles and mean
> > under both schemes, plotting rhoboot vs varboot is different. When I do
> > the plot for the bootstrap procedure including both statistic at once, it
> > is a clear dependence between the correlation and its variance. But, when
> > I bootstrap the statistic separately and I do the plot, the dependece is
> > not present in the graph.
> >
> > Any idea what is going on??
>
> Hi Rogelio
>
> Without seeing your code, its hard to know exactly whats happening, however,
> I'm willing to make a guess:
>
> Any time you're performing a bootstrap, you're drawing random samples with
> replacement. This process is intrinsically random, so its natural to expect
> small amounts of variance from one bootstrap to another. In this case,
> however, it doesn't sound like you're dealing with a little imprecision;
> rather, your results are changing dramatically. This in turn suggests the
> following:
>
> When you're bootstrapping your two statistics separately, you're drawing
> your samples in a different order.
> Its entirely possible that this discrepancy in the ordering is eliminating
> the correlation between the two data series.
>
> There are a few different ways that you can control for this. You can play
> games with the seed of the random number generator. Alternatively, you can
> create an index and use this to preserve the sampling order across
> variables. (I'm sure folks can suggest any number of better solutions)
>
> I will make one (general) suggestion.
>
> Conceptually, bootstraps are quite simple. However, there are a lot of
> different ways that you can shoot yourself in the foot. I often find that
> the easiest way to avoid trouble is to make things as simple as possible.
> Start out by implementing your own bootstrap using the randsample option
> (also contained inside Statistics Toolbox). Once you've done this a few
> times and have a really good understanding how you're applying this
> technique THEN move over to functions like bootstrp and bootci...
>
> regards,
>
> Richard

Thanks Richard,

I beleive that the discrepancy, as you mentioned, is done because I was resampling twice, so the variance estimand uses a different set of bootstrap variables than the correlation estimand. However, I didnt know that the result will be so different. I will try to work out the math for simpler statistics and see whats going on. By the way, I was trying to set the seed of the random generator but got lost with all different options! Do you know how to set the seed for the bootstrp function??

Rogelio

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com