Documentation |
Sample size and power of test
n = sampsizepwr(testtype,p0,p1)
n = sampsizepwr(testtype,p0,p1,power)
power = sampsizepwr(testtype,p0,p1,[],n)
p1 = sampsizepwr(testtype,p0,[],power,n)
[...] = sampsizepwr(...,n,param1,val1,param2,val2,...)
n = sampsizepwr(testtype,p0,p1) returns the sample size n required for a two-sided test of the specified type to have a power (probability of rejecting the null hypothesis when the alternative hypothesis is true) of 0.90 when the significance level (probability of rejecting the null hypothesis when the null hypothesis is true) is 0.05. p0 specifies parameter values under the null hypothesis. p1 specifies the single parameter value being tested under the alternative hypothesis.
The following values are available for testtype:
'z' — z-test for normally distributed data with known standard deviation. p0 is a two-element vector [mu0 sigma0] of the mean and standard deviation, respectively, under the null hypothesis. p1 is the value of the mean under the alternative hypothesis.
't' — t-test for normally distributed data with unknown standard deviation. p0 is a two-element vector [mu0 sigma0] of the mean and standard deviation, respectively, under the null hypothesis. p1 is the value of the mean under the alternative hypothesis.
'var' — Chi-square test of variance for normally distributed data. p0 is the variance under the null hypothesis. p1 is the variance under the alternative hypothesis.
'p' — Test of the p parameter (success probability) for a binomial distribution. p0 is the value of p under the null hypothesis. p1 is the value of p under the alternative hypothesis.
The 'p' test is a discrete test for which increasing the sample size does not always increase the power. For n values larger than 200, there may be values smaller than the returned n value that also produce the desired size and power.
n = sampsizepwr(testtype,p0,p1,power) returns the sample size n such that the power is power for the parameter value p1.
power = sampsizepwr(testtype,p0,p1,[],n) returns the power achieved for a sample size of n when the true parameter value is p1.
p1 = sampsizepwr(testtype,p0,[],power,n) returns the parameter value detectable with the specified sample size n and power power.
When computing p1 for the 'p' test, if no alternative can be rejected for a given null hypothesis and significance level, the function displays a warning message and returns NaN.
[...] = sampsizepwr(...,n,param1,val1,param2,val2,...) specifies one or more of the following name/value pairs:
'alpha' — Significance level of the test (default 0.05)
'tail' — The type of test is one of the following:
'both' — Two-sided test for an alternative not equal to p0
'right' — One-sided test for an alternative larger than p0
'left' — One-sided test for an alternative smaller than p0