Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

sampsizepwr - Sample size and power of test

Syntax

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,...)

Description

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:

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:

Examples

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.6770

Compute 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

See Also

vartest, ttest, ztest, binocdf

  


Recommended Products

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