- Utilize the "bootstrp" function to generate bootstrap samples for each individual dataset separately. You can read more about "bootstrp" function here: https://www.mathworks.com/help/stats/bootstrp.html
- For each bootstrap sample, try to compute the median using the “median” function. You can read more about it here: https://www.mathworks.com/help/matlab/ref/double.median.html
- Try to Calculate the differences between the medians of the two bootstrap samples.
- Use the differences to compute the confidence interval.
- Check if the confidence interval includes zero. This technique is called “Hypothesis Testing”.
Bootstrapping Two Medians with the "bootstrp" function
25 views (last 30 days)
Show older comments
Any idea on how to implement the Bootstrapping Two Medians method - here below explained - with the "bootstrp" function?
- Bootstrap each sample separately, creating the sampling distribution for each median.
- Then calculate the difference between the medians, and create the sampling distribution of those differences. This is the sampling distribution we care about.
- Once we have that distribution we can establish a confidence interval on that, and report the result.
- If the confidence interval does not include 0, we can reject the null hypothesis that there is no difference between the medians of the two conditions.
% the two samples to be used as inputs
x = normrnd(10, 2, [100, 1]);
y = normrnd(12, 3, [100, 1]);
% (1) Bootstrap each sample separately
boot_x = ?
boot_y = ?
0 Comments
Answers (1)
Ayush
on 30 Oct 2024 at 12:48
To implement “Bootstrapping Two Medians” method using the “bootstrp” function in MATLAB, you can follow these steps:
Here's how you could implement this in MATLAB:
% Generating the two samples
x = normrnd(10, 2, [100, 1]);
y = normrnd(12, 3, [100, 1]);
% Bootstrap each sample separately
numBootstraps = 1000;
bootFun = @(data) median(data);
% Generating bootstrap samples and calculate medians
boot_x = bootstrp(numBootstraps, bootFun, x);
boot_y = bootstrp(numBootstraps, bootFun, y);
median_diff = boot_x - boot_y;
alpha = 0.05; % For a 95% confidence interval
CI = prctile(median_diff, [100 * (alpha/2), 100 * (1 - alpha/2)]);
fprintf('Confidence Interval for the difference of medians: [%f, %f]\n', CI(1), CI(2));
% Hypothesis testing
if CI(1) > 0
fprintf('Reject the null hypothesis: there is a significant difference.\n');
elseif CI(2) < 0
fprintf('Reject the null hypothesis: there is a significant difference.\n');
else
fprintf('Fail to reject the null hypothesis: no significant difference.\n');
end
you can read more about "prctile" function here:
Hope it helps!
2 Comments
Ayush
on 31 Oct 2024 at 2:55
The question revolves around the standard usage of the "bootstrp" function. You should be able to write the code yourself with ease by referring to its documentation here: https://www.mathworks.com/help/stats/bootstrp.html.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!