1. USE an urn model function that takes the proportion of Democrats…
Question Answered step-by-step 1. USE an urn model function that takes the proportion of Democrats… 1. USE an urn model function that takes the proportion of Democrats p and the sample size N asarguments and returns the sample average if Democrats are 1s and Republicans are 0s. Call thefunction take_sample.2. Now assume p <- 0.45 and that your sample size is N = 100. Take a sample 10,000 times and savethe vector of mean(X) - p into an object called errors. Hint: use the function you wrote for exercise1 to write this in one line of code.3. The vector errors contains, for each simulated sample, the difference between the actual p and ourestimate ¯X . We refer to this difference as the error. Compute the average and make a histogram ofthe errors generated in the Monte Carlo simulation and select which of the following best describestheir distributions:mean(errors)hist(errors)A. The errors are all about 0.05.B. The error are all about -0.05.C. The errors are symmetrically distributed around 0.D. The errors range from -1 to 1.16.5. EXERCISES 2994. The error ¯X − p is a random variable. In practice, the error is not observed because we do not knowp. Here we observe it because we constructed the simulation. What is the average size of the error ifwe define the size by taking the absolute value | ¯X − p | ?5. The standard error is related to the typical size of the error we make when predicting. We say sizebecause we just saw that the errors are centered around 0, so thus the averate error value 0. Formathematical reasons related to the Central Limit Theorem, we actually use the standard deviationof errors rather than the average of the absolute values to quantify the typical size. What is thisstandard deviation of the errors?6. The theory we just learned tells us what this standard deviation is going to be because it is the standarderror of ¯X . What does theory tell us is the standard error of ¯X for a sample size of 100.7. In practice, we don't know p, so we construct an estimate of the theoretical prediction based by pluggingin ¯X for p. Compute this estimate. Set the seed at 1 with set.seed(1).8. Note how close the standard error estimates obtained from the Monte Carlo simulation (exercise 5),the theoretical prediction (exercise 6), and the estimate of the theoretical prediction (exercise 7) are.The theory is working and it gives us a practical approach to knowing the typical error we will make ifwe predict p with ¯X . Another advantage that the theoretical result provides is that it gives an idea ofhow large a sample size is required to obtain the precision we need. Earlier we learned that the largeststandard errors occur for p = 0.5. Create a plot of the largest standard error for N ranging from 100to 5,000. Based on this plot, how large does the sample size have to be to have a standard error ofabout 1%?A. 100B. 500C. 2,500D. 4,0009. For sample size N = 100, the central limit theorem tells us that the distribution of ¯X is:A. practically equal to p.B. approximately normal with expected value p and standard error√p(1 − p)/N.C. approximately normal with expected value ¯X and standard error√¯X(1 − ¯X)/N.D. not a random variable.10. Based on the answer from exercise 8, the error ¯X − p is:A. practically equal to 0.B. approximately normal with expected value 0 and standard error√p(1 − p)/N.C. approximately normal with expected value p and standard error√p(1 − p)/N.D. not a random variable.11. To corroborate your answer to exercise 9, make a qq-plot of the errors you generated in exercise 2 tosee if they follow a normal distribution.12. If p = 0.45 and N = 100 as in exercise 2, use the CLT to estimate the probability that ¯X > 0.5. Youcan assume you know p = 0.45 for this calculation.13. Assume you are in a practical situation and you don’t know p. Take a sample of size N = 100 andobtain a sample average of ¯X = 0.51. What is the CLT approximation for the probability that yourerror is equal or larger than 0.01? Math Statistics and Probability DSI 102 Share QuestionEmailCopy link Comments (0)


