%LMex100301_4th.m
syms f y
p=zeros(5,1);
f=int(6*y*(1-y),0,0.2)
p(1)=eval(f);
f=int(6*y*(1-y),.2,0.4)
p(2)=eval(f);
f=int(6*y*(1-y),.4,0.6)
p(3)=eval(f);
f=int(6*y*(1-y),.6,0.8)
p(4)=eval(f);
f=int(6*y*(1-y),.8,1)
p(5)=eval(f)
DATA=[0.18 0.06 0.27 0.58 0.98
0.55 0.24 0.58 0.97 0.36
0.48 0.11 0.59 0.15 0.53
0.29 0.46 0.21 0.39 0.89
0.34 0.09 0.64 0.52 0.64
0.71 0.56 0.48 0.44 0.40
0.80 0.83 0.02 0.10 0.51
0.43 0.14 0.74 0.75 0.22];
DATA=DATA(:);
edges=0:0.2:1;
[N,Bin]=histc(DATA,edges);
O=[sum(N(1:2));N(3);sum(N(4:end))];
n=length(DATA);
E=p*n;
E=[sum(E(1:2));E(3);sum(E(4:end))];
chi2=sum((O-E).^2./E);
df=length(E)-1;
fprintf('The chi-square statistic with %1.0f df is %5.2f\n',df,chi2)
criticalval=chi2inv(0.95,df);
if chi2 >=       criticalval
    disp('Reject null')
else
    disp('Fail to reject null')
end
df=length(E)-1;
pvalue=1-chi2cdf(chi2,df)
