Chapter 4 - STATISTICS FOR BUSINESS & ECONOMICS by Paul Newbold
*****************************************************************************
* CHAPTER 4 - STATISTICS FOR BUSINESS & ECONOMICS, 4th Ed., by Paul Newbold *
*****************************************************************************
*
* Example 4.1, page 131 to Example 4.3, page 134
*
* Please read these sections and examples carefully.  Be sure you understand
* the methodology.
*
*----------------------------------------------------------------------------
* Example 4.4, page 136
*
* The GEN1 command is used to generate the constants.  Where:
*
*    PX0  = Probability of 0 errors per page
*    PX1  = Probability of 1 error per page
*    PX2  = Probability of 2 errors per page
*    MEAN = Mean number of errors per page
*
* The PRINT command prints out the result of the variable specified.
*
GEN1 PX0=0.81
GEN1 PX1=0.17
GEN1 PX2=0.02
GEN1 MEAN=(0*PX0)+(1*PX1)+(2*PX2)
PRINT MEAN
*
*----------------------------------------------------------------------------
* Example 4.5, page 139
*
* The GEN1 command is used to generate the constants.  Where:
*
*    EXPECT2 = Expectation of the squares of the number of errors per page
*    VAR     = Variance of the mean number of errors per page
*    STD     = Standard deviation of the number of errors per page
*
* The **2 function on the GEN1 commands squares the variable specified and
* the SQRT function calculates the SQuare RooT of the variable specified.
*
GEN1 EXPECT2=((0**2)*PX0)+((1**2)*PX1)+((2**2)*PX2)
GEN1 VAR=EXPECT2-(MEAN**2)
GEN1 STD=SQRT(VAR)
PRINT EXPECT2 VAR STD
*
* The DELETE command is used to delete variables.  The format of the DELETE
* command is:
*
*     DELETE vars
*
* where:  vars = a list of variables to be deleted.
*
* All variables can be deleted with the command:
*
*     DELETE / ALL
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.6, page 140
*
* The GEN1 command is used to generate the constants.  Where:
*
*    MCOST  = Material costs
*    LABOR  = Labor costs per day
*    X      = Number of days to complete the project
*    PROB   = Subjective probability that project will be completed based
*            on X number of days
*
SAMPLE 1 5
READ X PROB / LIST
10  0.10
11  0.30
12  0.30
13  0.20
14  0.10
GEN1 MCOST=25000
GEN1 LABOR=900
*
* The mean (MEANX) number of days(X) to complete the project and the variance
* (SIGMA) is:
*
GENR M=X*PROB
*
* The STAT command with the SUMS= option is used to store the SUM of the
* variable X in the constant MEANX.
*
STAT M / SUMS=MEANX
GENR V=((X-MEANX)**2)*PROB
*
* The STAT command and the SUMS= option is used to store the sum of the
* variable V in the constant SIGMA.
*
STAT V / SUMS=SIGMA
PRINT MEANX SIGMA
*
* The Expected Cost (EXPECTC), variance (VAR) and standard deviation (STD)
* of the total cost C is:
*
GEN1 EXPECTC=MCOST+(LABOR*MEANX)
GEN1 VAR=(LABOR**2)*SIGMA
GEN1 STD=SQRT(VAR)
PRINT EXPECTC VAR STD
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.7, page 152
*
SAMPLE 1 2
READ X PX Y PY / LIST
-5  0.4   0  0.6
20  0.6  25  0.4
*
* The GEN1 command is used to calculate the Mean (MEANX) and Variance (SIGMAX)
* of the random variable X. 
*
GENR SX=X*PX
*
* The STAT command and SUMS= option is used to store the sum of the variable
* SX in the constant MEANX.
*
STAT SX / SUM=MEANX
GENR VX=((X-MEANX)**2)*PX
*
* The STAT command and SUMS= option is used to store the sum of the variable
* VX in the constant SIGMAX.
*
STAT VX / SUMS=SIGMAX
PRINT MEANX SIGMAX
*
* The GEN1 command is used to calculate the Mean Profit (EXPECTX) and Variance
* (VARX) from Strategy A.
*
GEN1 EXPECTX=10*MEANX
GEN1 VARX=100*SIGMAX
PRINT EXPECTX VARX
*
* The GEN1 command is used to calculate the Mean (MEANY) and Variance (SIGMAY)
* of the random variable Y.
*
GENR SY=Y*PY
*
* The STAT command and SUMS= option is used to store the sum of the variable
* SY in the constant MEANY.
*
STAT SY / SUMS=MEANY
GENR VY=((Y-MEANY)**2)*PY
*
* The STAT command and SUMS= option is used to store the sum of the variable
* VY in the constant SIGMAY.
*
STAT VY / SUMS=SIGMAY
PRINT MEANY SIGMAY
*
* The GEN1 command is used to calculate the Mean Profit (EXPECTY) and the
* Variance (VARY) from Strategy B.
*
GEN1 EXPECTY=10*MEANY
GEN1 VARY=100*SIGMAY
PRINT EXPECTY VARY
*
* The GEN1 command is used to calculate the Mean (E5X5Y) and Variance (VARXY)
* of the return from Strategy C.
*
GEN1 E5X5Y=5*MEANX+5*MEANY
GEN1 VARXY=(25*SIGMAX)+(25*SIGMAY)
PRINT E5X5Y VARXY
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.8, page 157
*
SAMPLE 1 2
READ X PX / LIST
0  0.6
1  0.4
SAMPLE 2 2
*
* The GEN1 command is used to calculate the variance of the Bernoulli
* distribution with a mean distribution, p=0.4.
*
GEN1 SIGMAX=PX*(1-PX)
PRINT SIGMAX
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.9, page 159
*
* The DISTRIB command provides functions of probability distributions.  SHAZAM
* calculates the Cumulative Distribution Function (CDF) and Probability
* Density Function (PDF) for a continuous random variable X.
*
* The general format of the DISTRIB command is:
*
*     DISTRIB vars / options
*
* where:  vars    = a list of variables
*         options = a list of the options that are required on the
*                   specified type of distribution
*
SAMPLE 1 6
READ X
0
1
2
3
4
5
*
* The TYPE=BINOMIAL option specifies that the Binomial Distribution is to be 
* estimated.  When a Binomial Distribution is estimated the N= and P= options
* must be specified.  N= the sample size and P= specifies the parameter value
* of the Binomial Distribution.  The PDF= options saves the Probability
* Density Functions for each observation in the variable PDF49.
*
DISTRIB X / TYPE=BINOMIAL N=5 P=0.4 PDF=PDF49 LIST
*
*----------------------------------------------------------------------------
* Example 4.10, page 160
*
GEN1 N=5
GEN1 P=0.4
*
* The GEN1 command is used to calculate the Mean/Expected Number of Sales
* (MEAN), Variance (VAR) and Standard Deviation (STD) for the number of sales.
*
GEN1 MEAN=N*P
GEN1 VAR=N*P*(1-P)
GEN1 STD=SQRT(VAR)
PRINT MEAN VAR STD
*
*----------------------------------------------------------------------------
* Example 4.11, page 161
*
* Recall that the PDFs from Example 4.9 are stored in the vector PDF49.  The
* Probability of 0 Success is stored in Row 1 of PDF49, the Probability of
* 1 Success is stored in Row 2 of PDF49 and so on to the Probability of 5
* Successes is stored in Row 5 of PDF49.
*
GEN1 P0=PDF49:1
GEN1 P1=PDF49:2
GEN1 P2=PDF49:3
GEN1 P3=PDF49:4
GEN1 P4=PDF49:5
GEN1 P5=PDF49:6
PRINT P0 P1 P2 P3
PRINT P4 P5
*
* The GEN1 command is used to calculate the probability that the number of
* successes is between 2 and 4 inclusive.
*
GEN1 P24=P2+P3+P4
PRINT P24
*
* Probability of at least one success.
*
GEN1 PATL1=P1+P2+P3+P4+P5
PRINT PATL1
*
* Alternatively, the probabilities for any discrete distribution sum to 1.
* So the probability of at least one success can be calculated with the
* GEN1 command in the following statement.
*
GEN1 PDD=1-P0
PRINT PDD
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.12, page 161
*
SAMPLE 1 21
READ X
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
*
* In this example, the Probability Density Function is stored in the vector
* PDF412.
*
DISTRIB X / TYPE=BINOMIAL N=20 P=0.9 LIST PDF=PDF412
*
GEN1 P18=PDF412:19
GEN1 P19=PDF412:20
GEN1 P20=PDF412:21
*
* The GEN1 command is used to calculate the probability at most 17 acceptances.
*
GEN1 P17=1-P18-P19-P20
PRINT P17
*
*----------------------------------------------------------------------------
* Example 4.13, page 162
*
* In this example, the Probability Density Function is stored in the vector
* PDF1 when the parameter value, P=0.10 and the sample size, N=20.
*
DISTRIB X / TYPE=BINOMIAL N=20 P=0.10 PDF=PDF1 LIST
GEN1 P0=PDF1:1
GEN1 P1=PDF1:2
*
* The GEN1 command is used to calculate the decision rule whether a company
* accepts a very large shipment when the proportion of defects in the
* shipment is 10% (p=0.10).
*
GEN1 ACC10=P0+P1
PRINT ACC10
*
* In this case, the parameter value, P=0.20 and the sample size, N=20.
*
DISTRIB X / TYPE=BINOMIAL N=20 P=0.20 PDF=PDF2 LIST
*
* If 20% of items in the shipment are defective. (P=0.20)
*
GEN1 P0=PDF2:1
GEN1 P1=PDF2:2
GEN1 ACC20=P0+P1
PRINT ACC20
*
* In this case, the parameter value, P=0.30 and the sample size, N=20.
*
DISTRIB X / TYPE=BINOMIAL N=20 P=0.30 PDF=PDF3 LIST
*
* If 30% of items in the shipment are defective.P=0.30
*
GEN1 P0=PDF3:1
GEN1 P1=PDF3:2
GEN1 ACC30=P0+P1
PRINT ACC30
*
DELETE / ALL
*
*----------------------------------------------------------------------------
* Example 4.14, page 165
*
SAMPLE 1 7
READ X
0
1
2
3
4
5
6
*
* The TYPE=HYPERGEO on the DISTRIB command indicates a Hypergeometric
* Distribution is to be estimated.  The options N= specifies the sample size,
* BIGN= specifies the population size, and BIGX= specifies the population
* number of successes for the Hypergeometric Distribution.  The PDF= option
* stores the Probability Density Functions in the variable PDF414.
*
* Note:  In a Hypergeometric Distribution, the value for N= cannot be larger
*        than the value for BIGN=.  Otherwise, the distribution cannot be
*        estimated in SHAZAM and an error message will result.
*
DISTRIB X / TYPE=HYPERGEO N=6 BIGN=20 BIGX=5 PDF=PDF414
*
* The probability of no defectives in the sample is stored in Row 1 of the
* constant PDF414.  The PRINT command is used to print out the probability.
* The GEN1 command is then used to store this probability in the constant P0.
*
PRINT PDF414:1
GEN1 P0=PDF414:1
*
* The probability of one defective in the sample.  The GEN1 command is then
* used to store this probability in the constant P1.
*
PRINT PDF414:2
GEN1 P1=PDF414:2
*
* The probability of acceptance with no defectives is calculated with the
* GEN1 command.
*
GEN1 ACCEPT=P0+P1
PRINT ACCEPT
*
DELETE / ALL
*
*-----------------------------------------------------------------------------
* Example 4.15, page 167
*
SAMPLE 1 5
READ X
0
1
2
3
4
*
* In this case, the TYPE=POISSON is specified with a MEAN=0.4.  The PDF=
* option saves the Probability Density Function for each observation in the
* variable PDF15.
*
DISTRIB X / TYPE=POISSON MEAN=0.4 PDF=PDF15
*
* The PRINT command is used to print out the vector of PDFs.  As you will
* notice the PDF of 0 strikes is stored in Row 1 and the PDF of 1 strike
* is stored in Row 2 of the vector PDF15.
*
PRINT PDF15
*
* The GEN1 command is used to calculate the probability of more than one
* strike in a year PDFGT1.  Notice, PDF15:1 represents the PDF when 0 strikes
* occur and the PDF15:2 is for the PDF with 1 strike.
* 
GEN1 PDFGT1=1-(PDF15:1)-(PDF15:2)
PRINT PDFGT1
*
*-----------------------------------------------------------------------------
* Example 4.16, page 169
*
SAMPLE 1 3
*
* In this example, the Poisson distribution is estimated with a MEAN=2.0.
*
DISTRIB X / TYPE=POISSON MEAN=2.0 PDF=PDF16
*
* The GEN1 command is used to calculate the probability of more than two
* arrivals in a 5 minute period PDFGT2.  Notice, PDF16:1 represents the PDF
* with 0 arrivals, PDF16:2 represents the PDF with 1 arrival, PDF16:3
* represents the PDF with 2 arrivals.
*
GEN1 PDFGT2=1-(PDF16:1)-(PDF16:2)-(PDF16:3)
PRINT PDFGT2
*
*-----------------------------------------------------------------------------
* Example 4.17, page 170
*
* In this example, the Poisson distribution is estimated with a MEAN=3.5.
*
DISTRIB X / TYPE=POISSON MEAN=3.5 PDF=PDF17
*
* The GEN1 command is used to calculate the probability of at least three
* filings for bankruptcy from 100 corporations PDFGE3.  Notice, PDF17:1
* represents the PDF with 0 filings, PDF17:2 represents the PDF with 1 filing,
* and PDF17:3 represents 2 filings.
*
GEN1 PDFGE3=1-(PDF17:1)-(PDF17:2)-(PDF17:3)
PRINT PDFGE3
*
*-----------------------------------------------------------------------------
*
STOP