RSS

Bootstrapping in Matlab

I’m not guru in Matlab, but recently, I’ve found some useful trick for boostrapping in matlab. In spite of rather “clear” and detailed built-in help (help bootstrp). I became confused while bootstap function that returns array of result.

For example:
we have the following sequence:
x=normrnd(5,10,1,100);      % R = normrnd(mu,sigma,m,n)
[mu,sigma]=normfit(x)
mu = 6.7482
sigma = 10.0960

%[muhat,sigmahat] = normfit(data) returns estimates of the mean, µ, %and standard deviation, σ, of the normal distribution given the data %in data.
Now if we want to bootstrap we do the following thing:
stats = bootstrp(100,'normfit',x);
But this structure returns only first parameter, only mu in this example.
But what can we do if we want to get mu and sigmahat at once?
so:
we define new function:
function musig = getmusig(x)
[mu,sig] = normfit(x);
musig = [mu,sig];

and then use it

stats = bootstrp(100,@getmusig,x)

Cheers
PS. Original help was found at http://www.mathworks.se/matlabcentral/newsreader/view_thread/263358#688362 posted by Tom Lane

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Your Comment