>
"Here is a program that will help you to do a chi-squared test. Hit return in order to load it.":
with(plots):
with(plottools):
with(linalg):
IndTest:=proc(M)
local r,i,m,c,s,C,R,x,T,R1,E,i1,i2,i3,i4,i5,i6,i7,i8,cs,df;
r:=nops(M);
c:=nops(M[1]);
C:=[];
R:=[];
R1:=[];
E:=[];
x:=0;
T:=0;
for i1 from 1 to r
do
x:=0;
for i2 from 1 to c
do
x:=M[i1][i2]+x;
od;
T:=x+T;
R:=[op(R),x];
od;
x:=0;
for i3 from 1 to c
do
x:=0;
for i4 from 1 to r
do
x:=M[i4][i3]+x;
od;
C:=[op(C),x];
od;
for i6 from 1 to r
do;
R1:=[];
for i5 from 1 to c
do
R1:=[op(R1),(R[i6]*C[i5]/T)];
od;
E:=[op(E),R1];
od;
cs:=0;
for i7 from 1 to r
do;
for i8 from 1 to c
do
cs:=cs+((E[i7][i8]-M[i7][i8])^2)/(E[i7][i8]);
od;
od;
df:=(r-1)*(c-1);
s:=evalf(100*(1-stats[statevalf,cdf,chisquare[df]](cs)));
lprint("The chi-squared value is",evalf(cs),"and there are",
df," degrees of freedom. As such we have a probability of about ",
s," percent that the null hypothesis is true and we see such a dramatic chi-squared value. Whether you reject or accept the null hypothesis will depend on the significance level at which you ran your hypothesis test. Here we also look at of chi-squared value as it sits with respect to the chi-squared distribution with ",df," degrees of freedom.
");
A1:=plot(stats[statevalf,pdf,chisquare[df]](y),y=0..cs+5);
A2:=pointplot({[cs,stats[statevalf,pdf,chisquare[df]](cs)]},color=blue,symbol=diamond,thickness=2):
display(A1,A2);
end:
Warning, the name arrow has been redefined
Warning, the name arrow has been redefined
Warning, `A1` is implicitly declared local to procedure `IndTest`
Warning, `A2` is implicitly declared local to procedure `IndTest`
>
"First plug in you table as follows";
M:=
[
[138,145,152],
[64,67,84],
[74,78,96]
];
"Here we view our table to make sure it looks good!";
matrix(M);
IndTest(M);
"The chi-squared value is", 1.497047018, "and there are", 4, " degrees of freedom. As such we have a probability of about ", 82.71644220, " percent that the null hypothesis is true and we see such a dramatic chi-squared value. Whether you reject or accept the null hypothesis will depend on the significance level at which you ran your hypothesis test. Here we also look at of chi-squared value as it sits with respect to the chi-squared distribution with ", 4, " degrees of freedom.\n"
>