?=================================================================== ? Discrminant analysis = ? User must define the data matrix with the following line: = ? = ? NAMELIST ; X = ... $ = ? = ? CALC command must be changed by user. = ? = ? Partition of the sample = ? = CALC ; N1 = number of observations in first group $ ?=================================================================== ? ? Obtain the moments for the first group. ? SAMPLE ; 1-N1 $ MATRIX ; XBAR1 = MEAN(X) ? ? Matrix of squares and cross products in deviation form. ? ; S1 = {N1 - 1} * XVCM(X) $ ? ? Obtain row of first observation and moments for second sample ? SAMPLE ; ALL $ CALC ; I2 = N1+1 ; NALL = N ; DF = NALL - 2 ; N2 = NALL - N1 $ SAMPLE ; I2 - NALL $ MATRIX ; XBAR2 = MEAN(X) ; S2 = {N2 - 1} * XVCM(X) ? ? Add these moments and multiply by 1/(N1+N2-2) ? ; V = 1/DF * MSUM(S1 , S2) ? ? Compute d and average of means ? ; D = SINV(V) | MDIF(XBAR1,XBAR2) $ ? ? Classify the sample observations ? SAMPLE ; ALL $ CALC ; DXB = (DOT(XBAR1,D) + DOT(XBAR2,D)) / 2 $ CREATE ; XD = DOT(X,D) ? ? Sample observation is classified group 1 if variable XD is greater than scalar DXB, group 2 ? if less than or equal. ? ; CLASS = XD > DXB ; GROUP = IND(1,N1) ? ? CLASS = 1 if classified to group 1, 0 for group 2. ? How well does the rule do? ? GROUP = 1 if in group 1 and 0 else, then RIGHT = 1 if CLASS = GROUP. ? ; RIGHT = CLASS=GROUP $ ? ? Examine results CALC ; HIT RATE = XBR(RIGHT) $ LIST ; GROUP,CLASS,RIGHT $ ? ? Is the correct classification rate significant? ? CROSSTAB ; LHS = GROUP ; RHS = CLASS $