home *** CD-ROM | disk | FTP | other *** search
- .MCD 20000 0
- .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
- .CMD FORMAT rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
- .CMD SET ORIGIN 0
- .CMD SET TOL 0.001000
- .CMD MARGIN 0
- .CMD LINELENGTH 78
- .CMD SET PRNCOLWIDTH 8
- .CMD SET PRNPRECISION 4
- .TXT 0 41 1 39
- a1,38,39,37
- Copyright (c) 1988 by MathSoft, Inc.
- .TXT 1 41 1 72
- a1,71,78,70
- /EQUATIONS FOR CALCULATING VALUES AND PERCENTAGE POINTS OF CHI-SQUARE
- .TXT 1 -63 1 38
- a1,37,77,36
- CHI-SQUARE TEST FOR GOODNESS OF FIT
- .TXT 2 -18 2 79
- a2,78,77,127
- The chi-square test can be used to test the fit of observations to a set of
- predicted frequencies or to a given distribution.
- .EQN 1 81 1 22
- Pchi_index_~1;10
- .EQN 0 26 1 31
- altneg(n)~if(mod(n,2),-1,1)
- .TXT 2 -107 3 80
- a3,79,77,224
- For example, suppose that an experiment can have five different outcomes, and
- that the predicted frequencies of these outcomes are in the vector E while
- the actual counts obtained in a set of experimental trials are in V:
- .EQN 0 79 10 81
- Pchi_s(chi2,v)~(chi2/2)^(v/2)/Γ(v/2)*(2/v+Pchi_index_$(altneg(Pchi_index_)*(chi2/2)^Pchi_index_)/(Pchi_index_!*(v/2+Pchi_index_)))
- .EQN 4 -79 5 11
- E~({5,1}÷.1÷.15÷.2÷.45÷.1)
- .EQN 0 16 5 10
- V~({5,1}÷9÷18÷17÷39÷12)
- .EQN 3 29 5 28
- chisquare~{55}((E*{55}V-V)^2/(E*{55}V)){49}
- .TXT 3 -45 1 43
- a1,42,72,41
- The chi-square statistic for E and V is:
- .TXT 3 0 1 20
- a1,19,45,18
- For this E and V,
- .EQN 0 20 1 20
- chisquare={18994}?
- .TXT 2 60 1 15
- a1,14,78,13
- [Ctrl][PgDn]
- .TXT 1 -80 1 15
- a1,14,77,13
- [Ctrl][PgDn]
- .EQN 1 81 9 49
- Pchi_i(chi2,v)~1/(2^(v/2)*Γ(v/2))*(2&chi2`t^(v/2-1)*exp(-t/2)&t)
- .TXT 1 -80 2 77
- a2,76,76,116
- The probability of a greater value of chisquare for observations randomly
- drawn from the predicted distribution is
- .EQN 3 6 1 20
- df~length(V)-1
- .EQN 0 30 1 28
- Qchi(chisquare,df)={18994}?
- .TXT 2 -36 3 79
- a3,78,76,174
- so the fit in this case is good. (Here Qchi gives the tail of the chi
- square distribution. The number of degrees of freedom is one less than the
- number of observations.)
- .TXT 4 0 2 80
- a2,79,77,119
- To test the fit at the α level, choose α and find the α percentage point for
- the chi-square distribution:
- .EQN 0 80 1 15
- TOL~.000001
- .EQN 2 0 1 73
- Pchi(chi2,v)~if(chi2<2,Pchi_s(chi2,v),Pchi_s(2,v)+Pchi_i(chi2,v))
- .EQN 1 -68 1 9
- α~.01
- .EQN 0 28 1 19
- X(α,df)={18994}?
- .EQN 1 40 1 33
- Qchi(chi2,v)~1-Pchi(chi2,v)
- .TXT 1 -80 2 76
- a2,75,76,119
- Since the calculated chisquare is less that this value, the observations
- agree with the model according to this test.
- .EQN 1 80 1 26
- x~if(df≈1,.5,1.5*df)
- .EQN 0 29 1 34
- X(α,df)~root(Qchi(x,df)-α,x)
- .TXT 2 -109 1 15
- a1,14,76,13
- [Ctrl][PgDn]
- .TXT 2 0 5 79
- a5,78,76,342
- To test the fit of data to a given distribution, you can use MathCAD's
- histogram function to group the data into intervals, and compare the actual
- count with the expected count using the chi-square statistic. The equations
- below illustrate the process by testing a set of 200 normal(0,1) deviates
- for a fit with the normal distribution.
- .TXT 6 0 1 24
- a1,23,78,22
- 1. Draw the deviates:
- .EQN 0 24 1 13
- i~0;199
- .EQN 1 0 3 37
- d[i~\(-2*ln(rnd(1)))*cos(2*π*rnd(1))
- .TXT 4 -24 1 23
- a1,22,76,21
- 2. Set up intervals:
- .EQN 0 24 1 11
- n~0;7
- .EQN 2 0 2 21
- bins[n~.5*n-1.75
- .EQN 0 24 2 13
- bins[0~-10
- .EQN 0 16 2 12
- bins[7~10
- .TXT 3 -64 1 15
- a1,14,76,13
- [Ctrl][PgDn]
- .TXT 2 0 3 23
- a3,22,20,53
- 3. Find the expected
- count in each
- interval:
- .EQN 0 24 1 11
- k~0;6
- .EQN 2 0 2 42
- N[k~200*(cnorm(bins[(k+1))-cnorm(bins[k))
- .TXT 3 -24 3 22
- a3,21,19,54
- 4. Find the actual
- count in each
- interval
- .EQN 0 24 1 18
- A~hist(bins,d)
- .EQN 1 23 7 16
- N=?
- .EQN 0 18 7 12
- A=?
- .TXT 3 -65 1 38
- a1,37,76,36
- The expected and actual counts are:
- .TXT 2 0 1 41
- a1,40,75,39
- 5. Calculate the chi square statistic:
- .EQN 1 4 5 25
- chisquare~{55}((N-A)^2/N){49}
- .EQN 3 31 1 20
- chisquare={18994}?
- .TXT 3 -35 1 15
- a1,14,75,13
- [Ctrl][PgDn]
- .TXT 3 1 1 72
- a1,71,74,70
- 6. Choose α and find the α percentage point for 6 degrees of freedom:
- .EQN 2 4 1 9
- α~.25
- .EQN 0 13 1 17
- X(α,6)={18994}?
- .TXT 2 -17 1 68
- a1,67,75,66
- If chisquare is less than X(α,6), the fit is good at the α level.
-