File Exchange

image thumbnail

Permutation Test

version 2021.1.13.0 (25.6 KB) by Laurens R Krol
A permutation test (aka randomization test) for MATLAB, testing for a difference in means between two samples.


Updated 13 Jan 2021

From GitHub

View Version History

View license on GitHub

A permutation test (aka randomization test) for MATLAB, testing for a difference in means between two samples. It supports one- and two-tailed tests, and returns a p-value, the observed difference, and the effect size (Hedges g). The result can optionally be visualized using a histogram. It is also possible to perform exact tests, during which all possible permutations are considered.

Cite As

Laurens R Krol (2021). Permutation Test (, GitHub. Retrieved .

Comments and Ratings (9)

Kouichi C. Nakamura

Really useful, thanks. What is the effect size here? There are a dozen definitions and one used here is similar to Cohen's d, but not the same. I can't find the match in the Wikipedia article about Effect size.

P.S. If you want to make this function work smoothly for newer MATLAB versions at the expense of back-compatibility, I'm happy to make a simple Pull Request to replace inputParser with arguments blocks. Up to you.

Bryan Wingert

Fails in 2019b due to deprecated call to 'hist' on line 160. Correcting to 'histogram' resolves it.

Ting Lv

Laurens R Krol

Dear Miguel, this sounds like a comma might have accidentally been deleted on your end. Please re-download the exact file provided here and run it again. If you continue to have issues, it would be better if you could open a new issue on GitHub:

Miguel Lujan

If I try to run the exact same example that you provided:

sample1 = randn(1,5000);
sample2 = randn(1,5000) + .1;
permutationTest(sample1, sample2, 10000, 'plotresult', 1);

The code gives the "Error: File: permutationTest.m Line: 81 Column: 80
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct
matrices, use brackets instead of parentheses". I am a beginner in MATLAB coding. Is there anyway to workaround this?

Anna Mary Mc Cann

Thanks for this code, very easy to use and understand.

Manfred Oswald

Danilo La Terra

Cooper Penner

Works really well! Thanks for the upload :)

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!