www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ComputeSampleSizeForSelectedPowerValueExample.m
%% Compute Sample Size for Selected Power Value % Copyright 2015 The MathWorks, Inc. %% % A company runs a manufacturing process that fills empty bottles with % 100 mL of liquid. To monitor quality, the company randomly selects % several bottles and measures the volume of liquid inside. %% % Determine the sample size the company must use if it wants to detect a % difference between 100 mL and 102 mL with a power of 0.80. Assume that % prior evidence indicates a standard deviation of 5 mL. nout = sampsizepwr('t',[100 5],102,0.80) %% % The company must test 52 bottles to detect the difference between % a mean volume of 100 mL and 102 mL with a power of 0.80. %% % Generate a power curve to visualize how the sample size affects the power % of the test. nn = 1:100; pwrout = sampsizepwr('t',[100 5],102,[],nn); figure; plot(nn,pwrout,'b-',nout,0.8,'ro') title('Power versus Sample Size') xlabel('Sample Size') ylabel('Power')