www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ComputePowerForATwoSampleTTestExample.m
%% Compute Power for a Two-Sample t-Test % Copyright 2015 The MathWorks, Inc. %% % A farmer wants to test the impact of two different types of fertilizer on % the yield of his bean crops. He currently uses Fertilizer A, but believes % that Fertilizer B might improve crop yield. Because Fertilizer B is more % expensive than Fertilizer A, the farmer wants to limit the number of plans he % treats with Fertilizer B in this experiment. %% % The farmer uses a 2:1 ratio of plants in each treatment group. % He tests 10 plants with Fertilizer A, and 5 plants with % Fertilizer B. The mean yield using Fertilizer A is 1.4 kg per plant, % with a standard deviation of 0.2. The mean yield using Fertilizer B is % 1.7 kg per plant. The significance level of the test is 0.05. %% % Compute the power of the test. pwr = sampsizepwr('t2',[1.4 0.2],1.7,[],5,'Ratio',2) %% % The farmer wants to increase the power of the test to 0.90. Calculate how % many plants he must treat with each type of fertilizer. n = sampsizepwr('t2',[1.4 0.2],1.7,0.9,[]) %% % To increase the power of the test to 0.90, the farmer must test 11 plants % with each type of fertilizer. %% % The farmer wants to reduce the number of plants he must treat with % Fertilizer B, but keep the power of the test at 0.90. but % maintain the initial 2:1 ratio of plants in each treatment group %% % Using a 2:1 ratio of plants in each treatment group, calculate how many % plants the farmer must test to obtain a power of 0.90. Use the mean and % standard deviation values obtained in the previous test. [n1out,n2out] = sampsizepwr('t2',[1.4,0.2],1.7,0.9,[],'Ratio',2) %% % To obtain a power of 0.90. the farmer must treat 16 plants with % Fertilizer A and 8 plants with Fertilizer B.