| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
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
Compute the mean closest to 100 that can be determined to be significantly different from 100 using a t-test with a sample size of 60 and a power of 0.8.
mu1 = sampsizepwr('t',[100 10],[],0.8,60)
mu1 =
103.6770Compute the sample size n required to distinguish p = 0.26 from p = 0.6 with a binomial test. The result is approximate, so make a plot to see if any smaller n values also have the required power of 0.5.
napprox = sampsizepwr('p',0.2,0.26,0.6)
Warning: Values N>200 are approximate. Plotting the power as a function
of N may reveal lower N values that have the required power.
napprox =
244
nn = 1:250;
pwr = sampsizepwr('p',0.2,0.26,[],nn);
nexact = min(nn(pwr>=0.6))
nexact =
213
plot(nn,pwr,'b-',[napprox nexact],pwr([napprox nexact]),'ro');
grid on

vartest, ttest, ztest, binocdf
![]() | SampleWithReplacement property (TreeBagger) | scatterhist | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |