Chapter 4 AppendixProbability: The Study of Randomness with Excel, JMP, Minitab, SPSS, CrunchIt!, R, and TI-83/-84 Calculators

TA4-1

Randomness

Random phenomena are the basis of probability studies. What will be the result of the next flip of a coin? What will be the sex of the next baby born today at your local hospital? The result of a toss of two dice? Most of these technologies can generate random numbers to help in the simulations of this section.

image

  1. Data ➔ Data Analysis ➔ Random Number Generation
  2. Enter the number of variables (columns) you wish to generate and the number of rows.
  3. Select the type of distribution from the drop-down box.
  4. Enter the parameters of the distribution.
  5. Enter an output range (the default is a new worksheet).

Examples:

If you want to simulate repeated tosses of a fair coin, use Bernoulli with .

If you want to simulate tossing a die, enter the values 1 through 6 in one column and the probabilities in an adjacent column. Select “Discrete,” and specify that range as the “Value and Probability Input Range.” To simulate tossing two dice, generate two columns and then add the results into a third.

image

  1. Right-click on the header of an empty column in a new worksheet (otherwise, you may not get as many random numbers as you wish).
  2. Column Info ➔ Initialize Data ➔ Random
  3. In the dialog box, select the type of random numbers you want. For integers between a and b, select “Random Integer” and enter a and b. For numbers between 0 and 1, select “Random Uniform.” For simple 0 or 1 data (as in flipping a coin), select either “Random Integer” or “Random Indicator.”

To simulate tossing two dice, generate two columns of Random Integer data between 1 and 6, then right-click in a new column, and select “Formula.” Enter a formula by clicking the variables just created. The command would look like

Column1+Column2

TA4-2

image

  1. Calc ➔ Random Data
  2. Select the type. Minitab can generate random integers as well as data from many types of distributions.
  3. Enter the number of rows to generate, and the columns (as Cxx-Cyy) and the parameters of the distribution.
  4. Click “OK.”

For example, to simulate flips of a fair coin, you can use “Integer,” with 0 as the minimum and 1 as the maximum.

To simulate throwing a die, use “Integer” with 1 as the minimum and 6 as the maximum. For two dice, generate two single dice columns and add them together using Calc ➔ Calculator. Specify a new column for the result and enter the formula (as in ).

image

  1. Page down and enter some value in the first column of an empty worksheet to correspond with the number of random numbers you wish to generate. You may have to enter interim values to be able to go down as far as you want.
  2. Transform ➔ Compute Variable
  3. Enter a destination column name.
  4. In the “Function Group” box, select “Random Numbers.”
  5. Select the type of numbers (or distribution) you want from the list. A “help” screen will appear in the lower center of the dialog box to inform you of the parameters. Double-click on the type to transfer the shell to the formula box.
  6. Enter the parameters as specified by the help.

For example, to simulate flips of a fair coin, you can use RV.Bernoulli, with 0.5 as the probability.

To simulate throwing a die, use RV.Uniform with 1 as the minimum and 7 as the maximum. Truncate that result to integer using Transform ➔ Compute Variable with Trunc from the “Arithmetic” function group. For two dice, generate two single dice columns and add them together using Transform ➔ Compute Variable. Specify a new column for the result and enter the formula (as in ).

image

  1. Insert ➔ Random Numbers
  2. Select the type you want.
  3. Enter the parameters and the number of samples (rows).
  4. Click “Calculate.”

To simulate flipping a fair coin, use Binomial with and . There is no ability to simulate events like throwing dice at this time.

image

TI calculators can simulate random integers (equally likely) or observations from Normal and Binomial distributions. For random integers,

  1. Press image image image (to PRB) and select .
  2. Specify the parameters: min,man,n. Close the parentheses.
  3. Press image to store the results in L1.

To simulate 100 flips of a fair coin, the command would look like

randInt(0,1,100)➔L1.

To simulate throwing a pair of dice, generate two lists using 1 as the minimum and 6 as the maximum (say, into L1 and L2); place the cursor in the list header for L3 in the statistics editor and enter the formula .

TA4-3

image

R has many ways to generate random numbers; for equally likely integers, the easiest is to use a command like

> x <- sample(min:max,n,replace=TRUE)

100 tosses of a die would look like

> x <-sample(1:6,100,replace=TRUE)

To toss two dice, generate two sets and add the results as

> sum<-x+y

Random Variables

This section includes discussion on Normal distributions as random variables. Refer back to the Chapter 1 appendix to refresh your memory on computing these probabilities.

Means and Variances of Random Variables

Calculating the mean and variance of a discrete random variable can be done using software as a calculator.

image

  1. Enter the values of the variable in one column and the probabilities in a second.
  2. Place the cursor in a blank column adjacent to one of your columns.
  3. Enter a formula to multiply the probability and the value. For example,

    =A1*B1

  4. Drag the cursor to copy the formula down the rows.
  5. Place the cursor in an empty cell and enter a formula to sum the entries just created to find the mean; for example,

    =sum(C1..Cn)

  6. Calculate the variance as by once again placing the cursor in an empty cell (for example, D1) and entering the formula (assuming the mean is in cell F1)

    =(A1-F$1)^2*B1

  7. Sum the entries just created as was done in step 5.

image

  1. Enter the values of the variable in one column and the probabilities in a second.
  2. Analyze ➔ Distribution
  3. Click to enter the column with the variable values into Y, and the column with the probabilities into Weight. Click “OK.”

In the results, the mean given is and the standard deviation is . Square to find the variance.

TA4-4

image

Enter the values of the variable in one column and the probabilities in a second, say, C1 and C2.

This is easiest done with commands, so click in the “Session” window and then click Editor ➔ Enable Commands.

MTB> Let C3=C1*C2

MTB> Sum C3 (This displays the mean.)

MTB> Let C4=(C1-mean)**2*c2

MTB> Sum C4 (This displays the variance.)

image

  1. Enter the values of the variable in one column and the probabilities in a second, say, X and P.
  2. Transform ➔ Compute Variable
  3. Enter a new variable name (say, XP) and the formula X*P. Click “OK.”
  4. Analyze ➔ Descriptive Statistics ➔ Descriptives
  5. Click to enter the variable just created (XP in this example) as the variable and then “Options.” Check the box next to “Sum.” Click “Continue” and “OK.” The entry for the sum is the mean of the random variable.
  6. Transform ➔ Compute Variable
  7. Enter a new variable name (say, XMUSQ) and the formula

    (X-mean)**2*P

    where mean is the value just found. Click “OK.”

  8. Analyze ➔ Descriptive Statistics ➔ Descriptives
  9. Click to enter the variable just created (XMUSQ in this example). The sum displayed is the variance.

image

Crunchit cannot perform these calculations; at this time, you cannot obtain the sum of a column (variable).

image

  1. Enter the variable values in one list (say, L1) and the probabilities in another (say, L2).
  2. image (for )
  3. Enter the two list names separated by a comma. The command should look like

    1-VarStats L1,L2

  4. In the displayed results, is (the calculator only has one symbol for a mean), and is the population standard deviation.
  5. For the variance (without rounding error), press (Statistics) (for ) .

TA4-5

image

Calculate the mean as shown in the example commands below.

> x<-c(1,2,3,4,5)

> p<-c(.1,.2,.2,.1,.4)

> xp=x*p

> sum(xp)

[1] 3.5

Calculate the variance as shown in the example commands below.

> xmmusq=(x-3.5)**2*p

> sum(xmmusq)

[1] 2.05