Session Ready
Exercise

Exercise 2. Distribution of errors - 1

Assume the proportion of Democrats in the population \(p\) equals 0.45 and that your sample size \(N\) is 100 polled voters. The take_sample function you defined previously generates our estimate, \(\bar{X}\).

Replicate the random sampling 10,000 times and calculate \(p - \bar{X}\) for each random sample. Save these differences as a vector called errors. Find the average of errors and plot a histogram of the distribution.

Instructions
100 XP
  • The function take_sample that you defined in the previous exercise has already been run for you.
  • Use the replicate function to replicate subtracting the result of take_sample from the value of \(p\) 10,000 times.
  • Use the mean function to calculate the average of the differences between the sample average and actual value of \(p\).