Moderated t-test

Moderated t-test based on empirical Bayes techniques to improve statistical power


Updated 16 Aug 2023

View License

This packages provides an implementation of the moderated t-test, which utilizes an empirical Bayes method to shrink the sample variances towards a common value and augment the degrees of freedom for the individual variances, resulting in increased statistical power. It includes two functions: 'moderated_ttest' for one-sample or paired t-tests, and 'moderated_ttest2' for two-sample t-tests. For ease of use, these functions closely mirror the input and output structure of MATLAB's ttest and ttest2 functions and can be used interchangeably. The implementation is inspired from R's limma package and applies the techniques outlined in the Smyth (2004) paper.
Example Use:
% Load the example dataset
x = grades(:, 1);
y = grades(:, 2);
% Perform the test
[h,p,ci,stats] = moderated_ttest2(x, y)
h = 0
p = 0.9867
ci = 2x1
stats = struct with fields:
tstat: 0.0167
df: 238
sd: 7.7084
mean: 0.0167
sd_prior: 7.7084
df_prior: 0
When performing a single test, moderated t-test is equivalent to the standard t-test.
Perform tests for each row:
X = grades(:, 1:2);
Y = grades(:, 3:4);
% Compare results of first exam with 3rd and second with 4th
[h,p,ci,stats] = moderated_ttest2(X, Y, 'Dim', 2);
% Convert to table and display the first 3 results
T = struct2table(struct('Passed', h, 'PValue', p, 'CI', ci, ...
'TStat', stats.tstat, 'DF', stats.df, 'SD',;
disp(T(1:3, :));
Passed PValue CI TStat DF
______ _________ __________________ ________ ___
false 1 -8.5232 8.5232 0 360
false 0.90822 -9.0232 8.0232 -0.11537 360
false 0.17917 -2.6899 14.357 1.3459 360

Cite As

Serhan Yilmaz (2023). Moderated t-test (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!


Version Published Release Notes