Simulate n values of a Poisson random variable X = poisson(λ) (choose λ > 0). Compute the sample mean (x̄), sample median (m), and sample standard deviation (s). Plot these quantities as functions of n (following the "General remark" for incremental generation). Observe the limit values these statistics converge to as n → ∞. What are these limits? Compare with theory. Estimate the variance of x̄ and m for n = 100 using 10,000 repetitions to determine which estimate is better (smaller variance).
-
Parameters:
- λ (lambda, rate parameter of Poisson): Choose a value, e.g., λ = 10.
max_n: Maximum sample size for convergence plots, e.g., 10,000.step: Increment fornin convergence plots, e.g., 100.n_variance: Sample size for variance estimation, e.g.,n = 100.num_repetitions: Number of repetitions for variance estimation, e.g., 10,000.
-
Simulation (Incremental):
- Similar to Project 1, generate Poisson samples incrementally.
- Start with
n = stepsamples from poisson(λ). - For subsequent
nvalues (2*step,3*step, ...,max_n), addstepnew samples to the existing dataset. - Use
numpy.random.Generator.poisson(lam=λ, size=...).
-
Statistics Calculation:
- For each value of
nin the incremental simulation, calculate:- Sample Mean:
numpy.mean() - Sample Median:
numpy.median()(Note: Poisson is discrete, median will be an integer or half-integer). - Sample Standard Deviation:
numpy.std(ddof=1).
- Sample Mean:
- For each value of
-
Plotting Convergence & Theoretical Limits:
- Plot Sample Mean vs.
n, Sample Median vs.n, Sample Standard Deviation vs.non separate plots. - Theory: For X ~ poisson(λ):
- E[X] (True Mean) = λ
- Var(X) (True Variance) = λ
- True Standard Deviation = sqrt(λ)
- The median of a Poisson distribution is approximately floor(λ + 1/3 - 0.02/λ) for large λ, typically close to λ.
- Add horizontal lines on the plots representing the theoretical limits (λ for mean/median, sqrt(λ) for std dev) to check convergence.
- Plot Sample Mean vs.
-
Convergence Comparison (Variance Estimation):
- Similar to Project 1, set
n = n_variance(e.g., 100). - Repeat
num_repetitions(10,000) times:- Generate a new sample of
nvalues from poisson(λ). - Calculate the sample mean (x̄) and sample median (m).
- Generate a new sample of
- Collect the 10,000 means and 10,000 medians.
- Compute the sample variance of the collected means and medians.
- Compare the variances. The estimator with the smaller variance is better (more efficient) for this
n. - Theoretical Variance: Var(x̄) = Var(X)/n = λ/n. There isn't a simple formula for Var(m) for Poisson, but we expect it to be larger than Var(x̄).
- Similar to Project 1, set
-
Implementation:
project_16.pyandtest_project_16.py. Include visualizations for the convergence plots.