Use a script to perform a simple statistical experiment.
To help us discuss these questions, let's create two identical groups of subjects:
G1 = ( 88, 90, 79, 82, 99, 105, 91, 86, 74, 101, 80, 96 ). G2 = ( 88, 90, 79, 82, 99, 105, 91, 86, 74, 101, 80, 96 ).If we select five values from each group at random we might come up with:
G1 Sample = ( 90, 82, 105, 74, 80 ). Sample Mean: 86 G2 Sample = ( 88, 82, 99, 101, 86 ). Sample Mean: 91NOTE: sample means rounded to nearest whole
The actual average for each group is 89. So, you can see that random sampling doesn't guarantee that our samples will be very representative of our actual groups. In fact, we could wind up with random samples like this:
G1 Sample = ( 99, 105, 91, 101, 96 ) Sample Mean: 98 G2 Sample = ( 79, 82, 74, 80, 86 ) Sample Mean: 80Although the odds aren't very high that we will wind up with random samples yielding extremes (especially if we are dealing with large populations and sample sizes), there is always a possibility that this could happen. So, random sampling may not be very reliable if our sample size is small, but as our sample size increases the reliability of random sampling increases.
Random Sampling Script
Consider the following Perl script which illustrates the reliability of random sampling:
Notice the use of push to add an item to an array. This is a very useful trick in a lot of circumstances. One particularly useful context for this trick is when you are creating tables in a CGI script (something we'll discuss in unit four).
Also notice the use of srand(time) and the int rand($num) construct. The srand function seeds the random number generator with whatever input it is given. In this case we seed the random number generator with the current time (which is returned by the time function). The actual random number is generated by int rand($num). The int function converts the number returned by the rand function to an integer value. The rand function is given a number representing the size of our data array.
ASSIGNMENT:
Present the results to this activity on a web page.