[Return to Sta113 Home]

Sta113: Lab7 (Friday, March 21, 2003)

The task today is to implement hypothesis testing in MatLab.


A simple test of a normal mean should follow these steps:

Additionally we can examine the POWER of the test as a function of the true population mean.

Use this data of sample size n = 100 to perform the hypothesis test Ho: mu =< 4 vs. Ha: mu > 4, for alpha = 0.1. Then plot the power of the test as a function of the true population mean. Note that the population standard deviation is known to be 0.2. Use the following MatLab commands to do this.

 
% read in the data and call it something like "HT"
% first find the critical value since you already 
% know the hypothesis and the alpha level 

alpha = 0.1; 
n=length(HT);
std = 0.2;
Za = norminv(1-alpha,0,1);
CV = 4 + Za*std/sqrt(n);   % any test statistic greater than CV
                           % will lead to the rejection of the 
                           % null hypothesis, since we have a right
                           % tailed test


% what is the test statistic we have from the sample?

tstat = mean(HT); % does this fall in the rejection region?
                  % what if you have alpha = 0.05 instead?

Now we will look at the power of the hypothesis test. Remember that the power of the test is one minus the probability of making a type II error. This depends on the true value of the population mean instead of the hypothesized mean, so we will consider a range of possible values under the alternative hypothesis.

MU = 4:0.001:4.1;
POWER = 1- normcdf((CV - MU)/std*sqrt(n),0,1); % what is going on here?
plot(MU,POWER); % plot true mean verses power of test for
                % corresponding mean
xlabel('Mu');
ylabel('Power');

To see what is going on with the power of a hypothesis test take a look at this Java applet:

http://www.stat.sc.edu/~ogden/javahtml/power/power.html

If you understand this applet, then you should understand the type I, and type II errors, their probabilities, and power.