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.
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.
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
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 ).
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 ).
To simulate flipping a fair coin, use Binomial with and . There is no ability to simulate events like throwing dice at this time.
TI calculators can simulate random integers (equally likely) or observations from Normal and Binomial distributions. For random integers,
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
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.
Enter a formula to multiply the probability and the value. For example,
=A1*B1
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)
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
In the results, the mean given is and the standard deviation is . Square to find the variance.
TA4-4
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.)
Enter a new variable name (say, XMUSQ) and the formula
(X-mean)**2*P
where mean is the value just found. Click “OK.”
Crunchit cannot perform these calculations; at this time, you cannot obtain the sum of a column (variable).
Enter the two list names separated by a comma. The command should look like
1-VarStats L1,L2
TA4-5
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