So, I think what Matt provided helped a lot!
Now I am worrying about another part of the problem:
(f). Construct a second FOR loop script that determines the ratio of the estimates for which the true proportion falls within the 95% confidence interval of each of the estimates. If you’ve done it correctly, you should find that the true proportion was within the confidence interval for approximately 95% of your estimates.
I am a little bit confused what are we trying to find? Is it the ratio of the estimates? And will that be a single value or will be an array? Could anyone goot at Statistics help?
Here is what I got:
%% (d) Construct a for loop to loop through (a) through (c) 1000 times
clc,clear
loop_times = 1000;
sample_size = 500;
% number of success counter
u = rand(sample_size,loop_times); % Generate 500 samples from a uniform distribution
trueVal = 0.7;
number_of_success = sum(u<trueVal);
for k = 1:loop_times
for i = 1:sample_size
if u(i)<trueVal && u(i)>0
u(i) = 1; % Assign 1 to numbers between 0 and 0.7
number_of_success = number_of_success + 1;
else
u(i) = 0; % Assign 0 to numbers between 0.7 and 1
end
end
end
estimate_sample_proportion = number_of_success/loop_times; %array of 1000 estimates
standard_error = sqrt((estimate_sample_proportion .* (1 - estimate_sample_proportion))...
/ loop_times) % array of 1000 standard errors
% (f) Construct a second for loop to determind the ratio of the estimates
for j = 1: length(estimate_sample_proportion)
ratio_of_estimates = (estimate_sample_proportion(j) + 1.96 * standard_error(j)...
+ (estimate_sample_proportion(j) - 1.96 * standard_error(j)))/1
end