In past labs we've analyzed data. This time we're going to try something new; we're going to generate our own data. The purpose is to acquaint you with simulation studies. Simulation is a method that uses computers to help develop understanding about random processes. In effect, you pretend that the computer is tossing a coin, or pretend that the computer is randomly selecting a person from the population. The reason is that while it takes quite some time to flip a coin 1000 times, the computer can do this in an instant (more or less). So we can exploit this to gain some understanding about randomness.
1. Uniform Random Numbers.
Select a cell in your Excel Workbook. Type =rand()
(that's two parentheses: "(" followed by ")". )
then hit return. You'll get a random number between 0 and
1.
Select a cell and type: =rand()
Now select the lower right corner of the cell and drag it to extend
over several cells in the column. You've now generated several
random numbers.
Generate about 100 of these random numbers. Make a histogram of them. Describe the histogram. What's the average and the standard deviation?
Generate another list of 100 random numbers. Write down what you expect the histogram to look like: the same as the last, different, similar? Make a histogram and describe it, comparing it to the last histogram. Is the average of this list very different from the last time? Should it be?
Based on this two histograms, approximately what would you say is the probability of generating a number less than or equal to 0.5?
Now type: =rand()*2 + 3
and create about 100 of these random variables. Make a histogram.
How is this histogram different from the last two?
How would you generate a random number between 0 and 10? Between 10 and 20?
2. Coin Flips
The function INT( ) takes whatever number is inside the parentheses
and rounds it off to the nearest integer. Try it: type =int(1.22)
in a cell and hit return. Type =int(0.234) in a cell. You
should get 1 and 0, respectively. We can combine int and rand to
simulate flipping a coin. Type =int(rand()*2) in a cell and hit return.
If it comes up 0, we'll call that a tail, if it comes up 1, we'll call
that a head.
Generate100 "coinflips". How many heads do you expect to get? How many did you really get? (Note that you can quickly determine how many you got by selecting the entire column and hitting the summation sign button on the Excel Menu.)
You can easily repeat this experiment just by hitting the F9 key. You'll get a new list of coin tosses and a new total. Repeat this 25 times and make a list of the number of heads you get each time. Enter this list into a column of your worksheet and make a histogram of it. Describe the histogram. What was the average number of heads? What was the standard deviation? What would you say, roughly, is the probability of getting between 45 and 55 heads? Between 40 and 60? Between 35 and 65?
ANOTHER WAY: Choose the Random Number Generation from the Tools: Data Analysis menu. Select "bernoulli". Where it says "number of variables", type 1. Where it says "number of random numbers", type in as many as you'd like. Where it says "p value" type in .5. (Or any number between 0 and 1. This number represents the probability of getting a head on a single toss of a coin. You can experiment to see what "unfair" coins might look like.)
3. Normal Distribution
Using the Random Number Generator, select "normal" and create 50 random variables. Make a histogram and describe it. Where is it centered? How spread out is it?