Block 1: Random variables: Bernoulli and uniform
Week 10 · Probability II · Imai §6.3.1–6.3.2 · about 3 min
NoteHow this works
Run each cell with Run Code, look at the output, then answer the question at the end of the block. Every cell is editable; Start Over resets it. Errors are information: read them.
A random variable assigns a number to each outcome. Its distribution says how likely each value is: PMF (discrete), PDF (continuous) and CDF.
1. The uniform distribution
dunif() is a density, punif() the CDF.
2. Simulate a Bernoulli variable from a uniform one
y = 1 if the uniform draw x <= p, else 0.
Conclusion: With p = 0.5 and 1,000 draws, what does mean(y) show?
We get 0.494: the mean of Bernoulli draws estimates p, with sampling noise. A density can exceed 1 (dunif(0.5, 0, 0.1) = 10): only the area must be 1. More draws, smaller error: the law of large numbers.