Last version of MULTICOMPARE script
2 views (last 30 days)
Show older comments
Hi, I'm using an old version of multcompare script where I can't obtain the p-value, Could somebody send me the last version of this script?, or explain me which statistic test I have to use to obtain the p-values for multiple comparison test with Bonferroni adjustment. Thanks in advance.
0 Comments
Answers (1)
Aditya
on 22 Jul 2025
Hi Maria,
If you're using an older version of the multcompare script that doesn't provide p-values, you can still perform multiple comparison tests with Bonferroni adjustment by manually conducting pairwise comparisons between your groups and adjusting the resulting p-values. The typical approach is to use a two-sample t-test (ttest2) for each pair of groups if your data are approximately normally distributed; otherwise, you can use a nonparametric test like the Wilcoxon rank-sum test (ranksum). After calculating the p-values for all possible group pairs, you apply the Bonferroni correction by multiplying each p-value by the total number of comparisons. Here’s how you can do this in MATLAB:
groups = unique(G); % G: vector of group labels
k = numel(groups); % number of groups
m = k*(k-1)/2; % total number of pairwise comparisons
pvals = [];
pairs = [];
for i = 1:k-1
for j = i+1:k
x1 = X(G==groups(i)); % X: data vector
x2 = X(G==groups(j));
[~, p] = ttest2(x1, x2); % or use ranksum(x1, x2) if nonparametric
pvals(end+1,1) = min(1, p*m); % Bonferroni-adjusted p-value
pairs(end+1,:) = [groups(i) groups(j)];
end
end
result = table(pairs(:,1), pairs(:,2), pvals, 'VariableNames', {'Group1','Group2','Bonf_p'});
disp(result)
This code will output a table showing each pair of groups and their Bonferroni-adjusted p-values, allowing you to identify which group differences are statistically significant after correction.
0 Comments
See Also
Categories
Find more on Analysis of Variance and Covariance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!