Bayesian Monte Carlo and MCMCLesson 70 of 76 · 9 min
Sample a posterior directly
Use independent posterior draws to estimate a posterior probability with a numerical error check.
Once a posterior distribution is available, Monte Carlo can estimate a probability or expectation under it. Direct beta draws are independent in this example, so the ordinary independent-sample standard error applies to their average or event indicator.
The question is P(p above 0.6 given the invented observations and prior), not the probability of more than 60 percent successes in a future group. Each draw is one possible parameter value under the posterior. Averaging its threshold indicator estimates the posterior probability of that event.
SciPy supplies an exact beta survival function for comparison. This benchmark separates numerical approximation error from posterior uncertainty about p. Raising the draw count improves numerical precision; it does not add observations or narrow the exact posterior distribution.
- Independent posterior draws
- Posterior event probability
- Numerical standard error
Does increasing posterior draws from 1,000 to 100,000 supply more observed evidence?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Posterior P(p > .6), Monte Carlo: 0.45405 Independent-draw MCSE: 0.00352 Exact posterior probability: 0.45296 Posterior outcome SD of p: 0.08286
Read the first result
Posterior SD describes uncertainty about p; MCSE describes numerical error in the estimated posterior event probability. Both are dimensionless, but their target quantities and interpretations differ.
Try an edit
Replace event = p > .6 with event = p > .7 and Posterior P(p > .6), Monte Carlo: with Posterior P(p > .7), Monte Carlo: and stats.beta.sf(.6,a,b) with stats.beta.sf(.7,a,b). Select Run Python again. Compare the new Monte Carlo event estimate with Exact posterior probability and the size of Independent-draw MCSE. Does Posterior outcome SD of p change?
Scope. Independent beta sampling is a convenient benchmark. Correlated Markov-chain draws need different numerical error diagnostics.
Try a fresh case
A posterior mean estimate becomes numerically very precise. What follows?
Need a hint?
Hint 1
Separate the distribution being sampled from its numerical approximation.
Hint 2
Inspect the posterior SD as well as MCSE.