%variancetest.m
%Statistical test for variance. 
%To check the outcome of the random
%variable X %that are from Gaussian distributed with the particular %variance 
DATA=[89.6790 89.8510 90.0433 89.9077 90.0954 ...
    90.1265 89.7059 89.9441 89.3258 90.3622 ... 
    89.8011 89.6193 89.9197 89.5482 89.9934 ...
    89.8227 90.6887 90.3600 89.2104 90.1396] 
v=var(DATA);
disp('Hypothesis test for variance test')
disp('Null Hypothesis:variance is equal to 0.1')
s=((15-1)*v)/(0.1); 
%s follows chi-square distribution with order 15-1 
c=cumsum((pdf('chi2',0:0.1:50,19)/10));
t=0:0.1:50; 
plot(t,c); 
%Locating 0.05 significant level (95% confident level) %is the value at which the cumulative distribution is %0.05 and 0.95 
[p1,q1]=find((c-0.05)>0); 
[p2,q2]=find((c-0.95)>0); 
hold on
plot([t(q1(1)) t(q1(1))],[0 c(q1(1))],'-r*')
hold on 
plot([t(q2(1)) t(q2(1))],[0 c(q2(1))],'-r*')
plot(s,0,'bo')
%We reject the Hypotheis if s is greater than t(q1(1)) %or less than t(q2(1)) 
if(s>t(q2(1))) 
    disp('Reject the Null Hypothesis (i.e., var is equal to 0.1)') 
else
    disp('Accept the Null Hypothesis (i.e., var is equal to 0.1)') 
end
