I have done part a to c, got stuck on part d
the description of part a, b, and c is below:
(a) Begin by writing a script that will generate 500 samples drawn from a uniform distribution. We want to implement a true proportion of 0.7 (e.g., 70% of people are in favor of some new law). In the end, you should have an array filled with 1’s and 0’s, where any random number between 0 and 0.7 is assigned a 1, and any random number between 0.7 and 1 is assigned a 0.
(b) Write a script that will compute the proportion of the sample from part (a), which is an estimate of the true proportion. Use it to verify that you did part (a) correctly; the estimate should be fairly close to the true value.
(c) Write a script that computes the standard error of the estimate of the proportion. You must pretend that you don’t know the true proportion, so must use the estimate.
For part d, I was asked to construct a for loop to loop through step a to c 1000 times, each time through, I will take 500 smaples and estimate the proportion. In the end, I will have an array of 1000 estimates. I will also have an array of 1000 associated standard errors of the estimates.
I am assuming we are using nested for loop in this case, but I kept getting "number of success" as single value in script. I attached my code below, please help me to check where I did wrong!
if u(i)<trueVal && u(i)>0
number_of_success = number_of_success + 1;
estimate_sample_proportion = number_of_success/sample_size;
standard_error = sqrt((estimate_sample_proportion * (1 - estimate_sample_proportion))...