Premium problem132. Monte Carlo Estimate With a Confidence Interval

Medium Locked

Simulate n independent Bernoulli(p_true) trials and return (estimate, lower, upper): the observed proportion and a 95% confidence interval for it.

SE=p^(1−p^)n,CI=p^±1.96 SESE = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}, \qquad CI = \hat{p} \pm 1.96\,SE

An estimate without an interval is close to useless, because it gives no way to tell a converged answer from a noisy one. Note the interval narrows with n\sqrt{n}, so a tenfold improvement costs a hundred times the simulations.

Seed np.random.seed(seed) inside solve, immediately before drawing.

Input

p_true = 0.3
n = 10000
seed = 0

Output

(0.3055, 0.29647187000758185, 0.31452812999241814)

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)