How to bootstrap estimated Gamma parameters from sample 95% confidence

7 次查看(过去 30 天)
I've got a question I'm stuck on. I've attached the question below.
I have estimated the parameters alpha and beta (a and b) from question (b) using the method of moments, I am stuck on question (d).
I understand the general concept of bootstrapping (resampling data with replacement then reevaluating parameters) but I am confused about how to apply this, and how to determine a 95% confidence level.
I am using MATLAB. Any help is appreciated.
size(cow1) % checking size of cow1, document states 60 days but only 50 entries so will work off this.
mu_1 = mean(cow1) % mean of cow1 sample
mu_2 = mean(cow2) % mean of cow2 sample
mu_avg = ((mu_2+mu_1)/2)*0.05 % average of the two means to 5% significance
% difference between average of means to 5% significance and the difference in the sample means is negative
mu_avg - (mu_2 - mu_1) % this implies that the samples are not drawn from the same distribution
h=kstest2(cow1,cow2) % application of two-sample kolmogorov-smirnov test to further conclude that samples are not from same distribution
X = cat(2,cow1,cow2) % concatenate cow1 and cow2
mu_X = mean(X) % mean of concatenated array
i=1:100;
mu_X2 = sum((X(i)-mu_X).^2) % calculating necessary property for method of moments
alpha = (100*(mu_X)^2)/(mu_X2) % first parameter alpha using method of moments
theta = (1/(100*mu_X))*mu_X2 % second parameter theta using method of moments
gamfit(X) % using gamfit to check plausibility of estimated parameters
pd_gamma = makedist('Gamma','a',alpha,'b',theta)
Thanks in advance

回答(1 个)

Jeff Miller
Jeff Miller 2020-9-4
Generate 1000 (say) bootstrap samples from X.
For each sample, compute the parameter estimates, so in the end you have 1000 estimated values for each parameter.
Now look at a frequency distribution of the 1000 estimates for alpha. The middle 95% of this distribution defines the range of the 95% confidence interval for alpha. Analogously for the other parameter?
  2 个评论
Connor Cheema
Connor Cheema 2020-9-5
Hi Jeff, this is the data. Perhaps it will be useful. cow1 and cow2 need to be concatenated to make X.
I understand the theory, but I'm finding it hard to wrap my head around putting in to practice. Do I need to create a resampling with replacement loop in matlab, which runs each sample through a function that calculates the parameters? Can you show me how to do that?
cow1 = [7.0189 4.6956 4.2805 4.7935 5.5359 5.4631 7.6720 3.9343 3.2703 8.5008 ...
4.6744 7.5342 3.6222 6.2362 8.1941 10.9260 7.2358 5.2520 7.2005 5.3058 ...
5.4617 9.0420 4.5756 6.0729 4.8489 9.2165 6.0074 4.9991 5.6726 9.8731 ...
6.1737 8.1394 8.0198 3.9154 6.2223 5.1348 4.9408 6.8300 6.4502 4.7319 ...
6.6481 4.7097 7.1933 6.4782 6.6165 6.0350 5.7872 7.9257 10.4638 12.2806];
cow2 = [6.1822 10.9341 5.2125 5.2381 6.9940 4.5318 5.6065 7.7551 10.5300 6.7268 ...
8.9337 7.8130 5.6471 7.5956 4.5339 5.6056 5.7349 2.5753 10.7627 8.3561 ...
6.7613 6.5908 5.7342 5.5036 12.7741 6.6548 9.3067 3.6636 4.5011 8.8040 ...
12.0349 6.6749 5.7111 5.0153 6.5544 5.0972 8.9687 7.3994 8.2624 7.2778 ...
4.7936 6.5331 6.9889 7.2013 6.9641 4.9992 9.5769 10.9696 5.9341 4.9695];
Jeff Miller
Jeff Miller 2020-9-5
Well, I'd rather not do the assignment for you. But you can get a lot of help looking at the second example here: Bootstrapping Multiple Statistics. You need to make a function that computes alpha and theta for any given bootstrap sample, call it MyFun. You already have essentially the lines to do that:
alpha = (100*(mu_X)^2)/(mu_X2) % first parameter alpha using method of moments
theta = (1/(100*mu_X))*mu_X2 % second parameter theta using method of moments
so just wrap them in a function that gets X passed to it. Once you have that function, use this command to generate 1000 estimates of each parameter.
stats = bootstrp(1000,@MyFun,X);
Note that the bootstrp function is doing a lot of the hard work for you--generating all the bootstrap samples and accumulating the different values that you return from MyFun. At the end, stats will be an array with 1000 rows and 2 columns (or maybe vice versa) with the different parameter estimates generated by the bootstrapping process

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by