Quiz 9 (MSword): Due Begin of Class Mon, April 20

advertisement
Quiz 9 & 10 (20 points)
Due: Friday, April 17, 2008 beginning of class
Name__________________________
Exploring the Distribution of Sample Means by Computer Simulation
This is an individual assignment. You are allowed to seek help from persons other than me for programming
questions only. I reserve the right to verbally question you about your responses and assign a grade of zero if it
becomes apparent that the work was not your own. R has been installed in BRH-205, if you need to use
campus computing facilities.
Purpose: to investigate the distribution of sample means under different conditions using computer
simulations instead of theory.
1.
In this exercise, you will explore the distribution of sample means when the samples are drawn from
and Exp(2) distribution.
a. Using R, draw one random sample of size 3 from the Exp(2) distribution. You will use the
command rexp(n=3,rate=2). In R “rate” is what we call λ, n is the sample size and “rexp”
stands for random generation from the exponential distribution. You can store your sample in
an object called “data” using the command, data <- rexp(n=3,rate=2). Type data to
view your sample.
Write your sample here: ______________________________
The sample mean is: ________ (In R, use the command: mean(data) )
b. Repeat part (a). Write the resulting sample and sample mean here: __________________
c. To understand the behavior of all possible sample means from samples of size 3, we need to
repeat part (a) many, many times and record the resulting sample means. This is tedious to do
by hand, so use the following lines of code to generate 1000 sample of size 3 from an Exp(2)
distribution. Note that # is the comment symbol in R. R will ignore everything on a line after #.
simdata <- rexp(n=3000,rate=2) #generate 3000 random samples from Exp(2)
matrixdata <- matrix(simdata,nrow=1000,ncol=3) #format simdata as matrix
Now type matrixdata to see the random samples you just generated. Note each row is one sample
of size 3. Since there are 1000 rows, we have 1000 samples of size 3.
Now get the sample mean of each row of data:
means.exp <- apply(matrixdata,1,mean)
#takes the mean of each row
means.exp
#print the 1000 sample means to the screen
hist(means.exp)
mean(means.exp)
sd(means.exp)
#histogram of the 1000 means from samples of size 3
#mean of the 1000 sample means
#standard deviation of the means
Estimate  X by the mean of the 1000 sample means: __________
How does the estimate compare to the true value of  X   
1

 ________ ?
Estimate  X using the 1000 sample means:_________________
How does it compare to the true value of  X 

n

1
 n
 _________?
Attach either a printout or a sketch of the histogram of the 1000 sample means. Do the sample
means appear to be normally distributed?________
2. Now repeat exercise 1 for samples of size 15. So start by generating 1000 random samples of size 15
from Exp(2).
simdata <- rexp(n=15000,rate=2)
matrixdata <- matrix(simdata,nrow=1000,ncol=15)
Type matrixdata[1:2,] to view the first two rows of the matrix
Use the same R commands are before to obtain the histogram, mean and standard deviation of the
1000 sample means for samples of size 15.
Estimate  X by the mean of the 1000 sample means: __________
How does the estimate compare to the true value of  X   
1

 ________ ?
Estimate  X using the 1000 sample means:_________________
How does it compare to the true value of  X 

n

1
 n
 _________?
Attach either a printout or a sketch of the histogram of the 1000 sample means. Does it look
normal?________
3. Now draw 1000 samples of size 3 from a N(0,1) distribution. Use the R commands:
simdata <- rnorm(n=3000,mean=0,sd=1)
matrixdata <- matrix(simdata,nrow=1000,ncol=3)
Estimate  X by the mean of the 1000 sample means: __________
How does the estimate compare to the true value of  X    ________ ?
Estimate  X using the 1000 sample means:_________________
How does it compare to the true value of  X 

n

1
n
 _________?
Attach either a printout or a sketch of the histogram of the 1000 sample means. Does it look
normal?________
4. Lastly, draw 1000 samples of size 15 from a N(0,1) distribution. Use the R commands:
simdata <- rnorm(n=15000,mean=0,sd=1)
matrixdata <- matrix(simdata,nrow=1000,ncol=15)
Estimate  X by the mean of the 1000 sample means: __________
How does the estimate compare to the true value of  X    ________ ?
Estimate  X using the 1000 sample means:_________________
How does it compare to the true value of  X 

n

1
n
 _________?
Attach either a printout or a sketch of the histogram of the 1000 sample means. Does it look
normal?________
5. Suppose X is the mean of a random sample of size 15 drawn from a population that has the N(0,1)
distribution.
a. Calculate P( X <0.25) using theory to obtain the exact probability. (To use R, look up the
command pnorm, i.e. type ?pnorm)
b. Approximate P( X <0.25) using the 1000 sample means simulated in problem 4. (Hint: sorting
the sample means in ascending order might help, use the R command sort(x), where x is the
name of the vector containing the sample means.)
6.
a. Redo problem #21a in section 4.7 of the Navidi text using a simulation. Compare your
approximation to the exact theoretic answer.
b. Let X = life of Bulb A and Y = life of Bulb B, use a simulation to determine if the following
random variables are approximately normal
i. Y/X
ii. sin(X)
c. Use a simulation to approximate the probability that Bulb B lasts over 10% longer than Bulb A.
d. In general, when using computer simulation methods to approximate probabilities, how can you
improve the accuracy of your approximation? For example, in part (c) what can you do to
increase the accuracy of your answer?
e. Are sample means always normally distributed?
Download