sampsizecalc

Version 1.0.0 (3.13 KB) by Andrew Penn
Simple sample size calculator
6 Downloads
Updated 22 Jan 2023

View License

Function file: sampsizecalc
N = sampsizecalc (TESTTYPE, EFFSZ)
N = sampsizecalc (TESTTYPE, EFFSZ, POW)
N = sampsizecalc (TESTTYPE, EFFSZ, POW, ALPHA)
N = sampsizecalc (TESTTYPE, EFFSZ, POW, ALPHA, TAILS)
Perform sample size calculations by power analysis.
N = sampsizecalc (TESTTYPE, EFFSZ) returns the required sample size to
reach the significance level (alpha) of 0.05 in a two-tailed version of
the test specified in TESTTYPE for the specified effect size, EFFSZ, with
a power of 0.8 (i.e. a type II error rate of 1 - 0.8 = 0.2)
TESTTYPE can be:
't2' (default) : two-sample unpaired t-test
't' : paired t-test or one-sample t-test
'z2' (default) : two-sample unpaired z-test (Normal approximation)
'z' : paired z-test or one-sample z-test (Normal approximation)
'r' : significance test for correlation
EFFSZ can be numeric value corresponding to the standardized effect
size: Cohen's d or h (when TESTTYPE is 't2', 't', 'z' or 'z'), or
Pearson's correlation coefficient (when TESTTYPE is 'r'). For
convenience, EFFSZ can also be one of the following strings:
'small' : which is 0.2 for Cohen's d (or h), or 0.1 for Pearson's r.
'medium' : which is 0.5 for Cohen's d (or h), or 0.3 for Pearson's r.
'large' : which is 0.8 for Cohen's d (or h), or 0.5 for Pearson's r.
N = sampsizecalc (TESTTYPE, EFFSZ, POW) also
sets the desired power of the test. The power corresponds to 1 - beta, where
beta is the type II error rate (i.e. the probability of not rejecting the
null hypothesis when it is actually false). (Default is 0.8)
N = sampsizecalc (TESTTYPE, EFFSZ, POW, ALPHA)
also sets the desired significance level, ALPHA, of the test. ALPHA
corresponds to the type I error rate (i.e. the probability of rejecting the
null hypothesis when it is actually true). (Default is 0.05)
HINT: If the test is expected to be among a family of tests, divide ALPHA
by the number of tests so that the sample size calculations will maintain the
desired power after correction for multiple comparisons.
N = sampsizecalc (TESTTYPE, EFFSZ, POW, ALPHA, TAILS)
also sets whether the test is one-sided or two-sided (Default is 2)
Author: Andrew Penn

Cite As

Andrew Penn (2024). sampsizecalc (https://www.mathworks.com/matlabcentral/fileexchange/123670-sampsizecalc), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007b
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
1.0.0