Chapter 15 - STATISTICS FOR BUSINESS & ECONOMICS by Paul Newbold
*****************************************************************************
* CHAPTER 15 - STATISTICS FOR BUSINESS & ECONOMICS, 4th Ed., by Paul Newbold*
*****************************************************************************
*
* Sample Mean for A-cars, B-cars, and C-cars on Page 596.
*
* The sample range for ACARS and BCARS is 1 to 7.  The last observation for
* CCARS is missing so the sample range for this variable is 1 to 6.  The
* default missing observation value of -99999 has been included in Table 15.1
* so all three variables can be read in with 7 data points.
*
SAMPLE 1 7
READ ACARS BCARS CCARS / LIST
22.2     24.6     22.7
19.9     23.1     21.9
20.3     22.0     23.3
21.4     23.5     24.1
21.2     23.6     22.1
21.0     22.1     23.4
20.3     23.5    -99999
*
* The SUM= option on the STAT command saves the sum of A-cars in the constant
* SUMA.  The MEAN= option saves the mean of A-cars in the constant MEANA.
*
STAT ACARS / SUM=SUMA MEAN=MEANA 
STAT BCARS / SUM=SUMB MEAN=MEANB 
*
* The SET SKIPMISS command is used before the sum of CCARS is calculated.  If
* the missing observation was included in the calculation the sum for CCARS
* would be incorrect.
*
SET SKIPMISS
STAT CCARS / SUM=SUMC MEAN=MEANC 
PRINT MEANA SUMA MEANB SUMB
PRINT MEANC SUMC
*
* The overall mean of A-cars, B-cars, and C-cars on page 599.  First the GEN1
* command is used to generate the constant for the number of A-cars, B-cars,
* and C-cars.  
*
GEN1 NA=7
GEN1 NB=7
GEN1 NC=6
GEN1 XBAR=(NA*MEANA+NB*MEANB+NC*MEANC)/(NA+NB+NC)
PRINT XBAR
*
* The variability of the first group, A-cars is defined as SS1.
*
GENR SSA=(ACARS-MEANA)**2
STAT SSA / SUM=SS1
PRINT SS1
*
* The variability of the second group, B-cars is defined as SS2.
*
GENR SSB=(BCARS-MEANB)**2
STAT SSB / SUM=SS2
PRINT SS2
*
* The variability of the third group, C-cars is defined as SS3.
*
GENR SSC=(CCARS-MEANC)**2
STAT SSC / SUM=SS3
PRINT SS3
*
* The Total Within-Groups variability is defined as SSW with the GEN1 command.
*
GEN1 SSW=SS1+SS2+SS3
PRINT SSW
*
* The Total Between-Groups Sum of Squares is defined as SSG with the GEN1
* command.
*
GEN1 SSG=NA*((MEANA-XBAR)**2)+NB*((MEANB-XBAR)**2)+NC*((MEANC-XBAR)**2)
PRINT SSG
*
* The Total Sum of Squares is defined as SST with the GEN1 command.
*
GEN1 SST=SSW+SSG
PRINT SST
*
* The Within-Groups Mean Square is defined as MSW with the GEN1 command.
*
GEN1 N=NA+NB+NC
GEN1 K=3
GEN1 MSW=SSW/(N-K)
PRINT MSW
*
* The Between-Groups Mean Square is defined as MSG with the GEN1 command.
*
GEN1 MSG=SSG/(K-1)
PRINT MSG
*
* The F-value is:
*
GEN1 F=MSG/MSW
PRINT F
*
* The above method to calculate the One-Way Analysis of Variance is the long
* way.  In SHAZAM, the One-Way Analysis of Variance can be easily calculated
* with the ANOVA option on the STAT command.
*
STAT ACARS BCARS CCARS / ANOVA
*
*----------------------------------------------------------------------------
* Example 15.1, page 603
*
SAMPLE 1 6
READ SCIAMER FORTUNE NEWYORK / LIST
15.75  12.63  9.27
11.55  11.46  8.28
11.16  10.77  8.15
 9.92   9.93  6.37
 9.23   9.87  6.37
 8.20   9.42  5.66
*
STAT SCIAMER FORTUNE NEWYORK / ANOVA
*-----------------------------------------------------------------------------
* Two-Way Analysis of Variance, page 624
*
SAMPLE 1 15
READ X1 / BYVAR LIST
25.0  25.4  25.2
24.8  24.8  24.5
26.1  26.3  26.2
24.1  24.4  24.4
24.0  23.6  24.1
READ X2 / BYVAR LIST
24.0  24.4  23.9
23.5  23.8  23.8
24.6  24.9  24.9
23.9  24.0  23.8
24.4  24.4  24.1
READ X3 / BYVAR LIST
25.9  25.8  25.4
25.2  25.0  25.4
25.7  25.9  25.5
24.0  23.6  23.5
25.1  25.2  25.3
*
* The Group Mean is calculated using the STAT command.  The STAT command
* automatically calculates the mean of the variable specified.  The MEAN=
* option stores the mean in a specified constant.
*
STAT X1 / MEAN=MEANX1
STAT X2 / MEAN=MEANX2
STAT X3 / MEAN=MEANX3
PRINT MEANX1 MEANX2 MEANX3
*
* The Block Mean is calculated using the GENR command with the SUM(x,n)
* function.  The GENR statement first sums the first 3 observations of
* X1 and then the next three etc until all 15 observations are done.  The
* values for X2 and X3 are repeated with a similiar GENR command.  The
* DO-loop is then used next to complete the Block Means calculation.
*
SAMPLE 1 5
GENR XBAR1=SUM(X1,3)
GENR XBAR2=SUM(X2,3)
GENR XBAR3=SUM(X3,3)
PRINT XBAR1 XBAR2 XBAR3
DO #=1,5
GEN1 NXBAR#=(XBAR1:#+XBAR2:#+XBAR3:#)/9
PRINT NXBAR#
ENDO
*
* The Cell Mean is calculated in a similar fashion as the Block Mean.  The
* GENR command is used.  Recall in the previous example of the Block Means
* the sums were calculated and stored in the vectors XBAR1, XBAR2, and XBAR3.
* The Cell Means for X11, X12, X13, X14, and X15 are stored in the vector
* X11.  The Cell Means for X21, X22, X23, X24, and X25 are stored in the
* vector X22 and X31, X32, X33, X34, and X35 are stored in the vector X33.
* All that needs to be done is to determine the average for each of the
* sums.
*
SAMPLE 1 5
GENR X11=XBAR1/3
GENR X22=XBAR2/3
GENR X33=XBAR3/3
PRINT X11 X22 X33
*
* The Overall Mean is calculated with the GEN1 command.  Recall that the
* mean of all sample observations was calculated in the Group Means example
* above.
*
GEN1 OVERALL=(MEANX1+MEANX2+MEANX3)/3
PRINT OVERALL
*
* The Two-Way Analysis of Variance Table for Fuel Consumption data of
* Table 15.10, page 628.
*
* The following information is supplied on page 628 and 630 of the textbook.
* The GEN1 command is used to generate the respective constants.
*
GEN1 K=3
GEN1 H=5
GEN1 L=3
GEN1 SSG=7.1565
GEN1 SSB=13.1517
GEN1 SSI=6.6045
GEN1 SSE=1.1600
GEN1 SST=28.0727
*
* The Mean Squares in Column 4 of Table 15.13 on page 630 are calculated
* using the formulas in Table 15.12 on page 629 and the GEN1 command.
*
GEN1 MSG=SSG/(K-1)
GEN1 MSB=SSB/(H-1)
GEN1 MSI=SSI/((K-1)*(H-1))
GEN1 MSE=SSE/(K*H*(L-1))
PRINT MSG MSB MSI MSE
*
* The F-ratios in Column 5 of Table 15.13 on page 630 are calculated using
* the formulas in Table 15.12 on page 629 and the GEN1 command.
*
GEN1 FSSG=MSG/MSE
GEN1 FSSB=MSB/MSE
GEN1 FSSI=MSI/MSE
PRINT FSSG FSSB FSSI
*
DELETE / ALL
*
*-----------------------------------------------------------------------------
* Example 15.3, page 631
*
* The GEN1 command is used to generate the constants required to compute the
* Mean Square found in the second table on page 632.
*
GEN1 SSG=62.04
GEN1 SSB=0.06
GEN1 SSI=1.85
GEN1 SSE=23.31
GEN1 SST=82.26
*
* The Degrees of Freedom for Tasks is equal to 1.  We know that the Degrees
* of Freedom Between Groups is defined as K-1.  In this case K-1=1, therefore,
* K=2.  In the case of Worker Type, the Degrees of Freedom=1.  The Degrees
* of Freedom is defined as H-1 so H=2.  The Degrees of Freedom for Error
* is equal to 63 and the Degrees of Freedom is defined as KH(L-1)=63.
*
GEN1 K=2
GEN1 H=2
GEN1 L=(63+(K*H))/(K*H)
PRINT L
*
* The GEN1 command is used to calculate the Mean Squares.
*
GEN1 MSG=SSG/(K-1)
GEN1 MSB=SSB/(H-1)
GEN1 MSI=SSI/((K-1)*(H-1))
GEN1 MSE=SSE/(K*H*(L-1))
PRINT MSG MSB MSI MSE
*
* The F-ratios are calculated using the formulas in Table 15.12 on page 629
* and the GEN1 command.
*
GEN1 FSSG=MSG/MSE
GEN1 FSSB=MSB/MSE
GEN1 FSSI=MSI/MSE
PRINT FSSG FSSB FSSI
*
DELETE / ALL
*
*-----------------------------------------------------------------------------
*
STOP