Module contents
Lesson 4 of 27Core 100 min

Estimators: bias, variance, MSE, consistency and the method of moments

Define what makes an estimator good: bias, variance, mean squared error and its decomposition, consistency, and relative efficiency. Introduce the first general construction method, the method of moments, and a tool used throughout the module: ADEMP simulation studies for honest evaluation of procedures.

After this lesson you can

  • Calculate bias, variance, and MSE of simple estimators and prove MSE = bias² + variance.
  • Prove estimator consistency with the law of large numbers and mean-square convergence.
  • Construct moment estimators for gamma, beta, and uniform distributions and detect estimates outside parameter space.
  • Compare estimators by relative efficiency (mean versus median under normal, Laplace, and t).
  • Design and run an ADEMP simulation study reporting bias, variance, and MSE with Monte Carlo error.
  • Explain why a biased estimator may have lower MSE than an unbiased one.

Before you start

Motivation: three numbers for the same latency

You measured service response time for n=40n = 40 requests. You want one number summarizing “typical latency” and have three calculators: the mean of 40 times, median, and trimmed mean (discard the lowest 20 %20\,\% and highest 20 %20\,\% and average the rest). On the same sample they produce three numbers. Another sample of 40 requests gives three more. None exactly matches the value you want to know, so the useful question is not “which number is right?” but “which procedure errs least when applied repeatedly to new samples?”

That sentence hides three decisions turned into mathematics here. What does error mean? A loss; squared error is convenient. What does “repeatedly” mean? The procedure’s sampling distribution, already seen last lesson. What does “least” mean? Average loss over that distribution, yielding mean squared error. This language explains why the answer changes with data tail weight, why a biased estimator can be useful, why an unbiased estimator can be useless, and how to build a first general estimator, the method of moments, which sometimes fails instructively.

A qualification for a meaningful comparison: mean, median, and trimmed mean estimate the same thing only if the distribution is symmetric about a center μ\mu. Under skewness (as with real right-tailed latency) they are three distinct estimands and comparing their error makes no sense; this common mistake appears in the warnings. Here assume symmetry and ask about efficiency.

The lesson also introduces a tool you will use through the module and research work: the simulation study with ADEMP structure. Every claim about bias, variance, or coverage can be checked with a short experiment, using the rigor (seeds, Monte Carlo error, multiple data mechanisms) serious papers require.

Estimator, estimand, and estimate

Work within a statistical model {Pθ:θ∈Θ}\{P_\theta : \theta \in \Theta\}: data are X1,…,Xn∼iidPθX_1, \dots, X_n \iid P_\theta for unknown θ\theta. What we want is not always all of θ\theta; it is a function ψ=g(θ)\psi = g(\theta) (mean, variance, quantile, event probability…).

These three levels differ, and confusing them causes constant reasoning errors:

ObjectWhat it isRandom?Example
estimand ψ=g(θ)\psi = g(\theta)a number of interestno, fixed and unknowntypical latency μ\mu
estimator TnT_na rule, a random variableyesXˉn=1n∑iXi\bar X_n = \frac{1}{n}\sum_i X_i
estimate ttthe rule’s value on actual datano, it already occurredxˉ=112.4 ms\bar x = 112.4\ \text{ms}

An estimator is a random variable and thus has sampling distribution, expectation, variance, and standard deviation. An estimator’s standard deviation is called its standard error. Properties studied here (bias, variance, consistency) all describe the procedure, averaged over samples that could have been observed. None says whether this particular estimate is near or far from ψ\psi; that needs inference in later lessons (intervals, tests).

For large-sample limits consider a sequence of estimators T1,T2,…T_1, T_2, \dots, one per sample size, treated as one object.

Bias, variance, and mean squared error

The first desirable quality is accuracy “on average.”

Zero bias for every θ\theta is essential: an estimator right on average at only one particular θ\theta (for example constant estimator T=5T = 5 when θ=5\theta = 5) is not unbiased. But bias is not the whole story: T=X1T = X_1 (use only the first observation) is unbiased for μ\mu yet ignores n−1n - 1 observations. An error measure must also penalize spread.

This is squared loss averaged over the sampling distribution. Its root, ECM⁡\sqrt{\operatorname{ECM}}, has the estimand’s units. Squaring is a convenient convention (differentiable, permits decomposition), not a law of nature; the decision theory lesson shows each loss defines its own “best estimator.”

Proof

This is the bias-variance decomposition of MSE. Write ψ=ψ(θ)\psi = \psi(\theta) and m=Eθ[T]m = \E_\theta[T], and add and subtract mm inside the square:

E[(T−ψ)2]=E[((T−m)+(m−ψ))2]=E[(T−m)2]+2(m−ψ) E[T−m]+(m−ψ)2.\E[(T - \psi)^2] = \E[((T - m) + (m - \psi))^2] = \E[(T - m)^2] + 2(m - \psi)\,\E[T - m] + (m - \psi)^2.

The cross term vanishes because E[T−m]=0\E[T - m] = 0, and m−ψm - \psi is constant. This leaves Var⁡(T)+(m−ψ)2\Var(T) + (m - \psi)^2.

∎

The decomposition says estimator error has two sources added in squares: bias (the shots’ center is far from the target) and variance (shots scatter). For an unbiased estimator MSE is variance, and typical error ECM⁡\sqrt{\operatorname{ECM}} is standard error.

The dartboard

To feel bias and variance together, fire many shots. Each shot in the next figure is a σ2\sigma^2 estimate calculated on a new sample using estimator ∑i(Xi−Xˉ)2/d\sum_i (X_i - \bar X)^2/d with divisor dd you choose. The target is at σ2=1\sigma^2 = 1.

InteractiveBias and variance dartboard
Shots: σ^2\hat\sigma^2 in 4000 samples of size n=10n = 10 (target σ2=1\sigma^2 = 1)
spread ±0.47truth
  • shots
  • center of shots
  • truth σ2\sigma^2
Exact MSE versus divisor, in units of σ4\sigma^4 (n=10n = 10)
n−1nn+1minimum d = 11.0
  • variance
  • bias²
  • MSE = bias² + variance
  • simulated MSE
Data distribution
10
n − 1.0 = 9.0
Bias (simulated)−0.007 ± 0.007
Exact bias0.000
Variance (simulated | exact)0.225 | 0.222
MSE (simulated)0.225 ± 0.006
Exact MSE = bias² + variance0.000 + 0.222 = 0.222
Optimal divisor n+1+κ(n−1)/nn + 1 + \kappa(n-1)/n (κ=0\kappa = 0)11.00, MSE 0.182
Each point estimates σ2\sigma^2 from a new sample of size nn; the histogram summarizes 4000 shots. With d=n−1d = n - 1 (Bessel), the center is on target but the cloud is wide. Move the divisor: center shifts lower (bias, orange) and the cloud narrows (variance, blue). Right: exact MSE decomposed into bias² and variance for all divisors, with simulated MSE as a hollow circle. For normal data, where is the minimum? Change the data law and notice how it moves.

With n=10n = 10 and normal data the figures are clear: with d=n−1d = n - 1 MSE is 2/9=0.22222/9 = 0.2222 (in σ4\sigma^4 units), all variance; with d=nd = n it falls to 0.190.19, and with d=n+1d = n + 1 to 2/11=0.18182/11 = 0.1818, 18 %18\,\% less than the unbiased estimator. The next section proves this.

Biased can be better

Proof

Under normality, SS⁡=σ2Q\operatorname{SS} = \sigma^2 Q with Q∼χn−12Q \sim \chi^2_{n-1}, so E[Q]=n−1\E[Q] = n - 1 and Var⁡(Q)=2(n−1)\Var(Q) = 2(n-1), hence E[Q2]=2(n−1)+(n−1)2=(n−1)(n+1)\E[Q^2] = 2(n-1) + (n-1)^2 = (n-1)(n+1). Then

ECM⁡(c SS⁡)σ4=E[(cQ−1)2]=c2 E[Q2]−2c E[Q]+1=c2(n2−1)−2c(n−1)+1.\frac{\operatorname{ECM}(c\,\operatorname{SS})}{\sigma^4} = \E\big[(cQ - 1)^2\big] = c^2\,\E[Q^2] - 2c\,\E[Q] + 1 = c^2(n^2 - 1) - 2c(n-1) + 1.

This is a parabola in cc minimized where its derivative vanishes: 2c(n2−1)−2(n−1)=02c(n^2-1) - 2(n-1) = 0, or c=1/(n+1)c = 1/(n+1). Substitution gives n2−1(n+1)2−2(n−1)n+1+1=1−n−1n+1=2n+1\frac{n^2 - 1}{(n+1)^2} - \frac{2(n-1)}{n+1} + 1 = 1 - \frac{n-1}{n+1} = \frac{2}{n+1}. The other two values evaluate the parabola at c=1/(n−1)c = 1/(n-1) and c=1/nc = 1/n.

∎

For n=10n = 10: 2/9=0.22222/9 = 0.2222 versus 19/100=0.1919/100 = 0.19 versus 2/11=0.18182/11 = 0.1818. Bessel’s correction produces the highest MSE of the three. The breakdown explains it: the unbiased estimator pays in variance for what it gains in bias. Multiplying by a factor below 1 (shrinking toward zero) introduces downward bias but reduces variance by the factor squared; the balance favors it while bias is small relative to spread.

Divisor n+1n + 1 is a normal-theory result. Under other laws, variance of S2S^2 is σ4(2n−1+κn)\sigma^4\big(\tfrac{2}{n-1} + \tfrac{\kappa}{n}\big), where κ\kappa is excess kurtosis (0 for normal, 3 for Laplace, 6 for exponential, −1.2-1.2 for uniform), and the same calculation gives optimal divisor

d∗=n+1+κ n−1n.d^\ast = n + 1 + \kappa\,\frac{n-1}{n}.

Positive kurtosis (heavier tails than normal) calls for more shrinkage, and negative kurtosis such as uniform calls for less. Check by changing the law in the previous figure: for exponential with n=10n = 10 the minimum is d∗=16.4d^\ast = 16.4, farther from n−1=9n - 1 = 9 than under normality. This is the kurtosis defined in the probability lesson on skewness and kurtosis.

When unbiasedness is absurd

Sometimes the only unbiased estimator is useless. Observe one variable X∼Pois⁡(λ)X \sim \Pois(\lambda) and estimate ψ(λ)=e−2λ\psi(\lambda) = e^{-2\lambda}, always in (0,1)(0, 1).

The lesson is not that unbiasedness is bad, but that it is a constraint like any other: sometimes cheap (mean), sometimes expensive (variance with small nn), sometimes leaving one absurd solution. Look at MSE or the loss you actually care about.

Consistency

Everything above fixes nn. A second minimum requirement is that enough data eventually make the estimator accurate.

This definition applies convergence in probability from probability to an estimator sequence. Mean-square consistency is convergence in L2L^2, and is stronger:

Proof

By Markov’s inequality applied to (Tn−ψ)2(T_n - \psi)^2, which is Chebyshev’s inequality for error, P(∣Tn−ψ∣>ε)≤ECM⁡(Tn)/ε2→0\Pr(\abs{T_n - \psi} > \eps) \le \operatorname{ECM}(T_n)/\eps^2 \to 0. Equivalence of the two assumption formulations follows from MSE decomposition. A counterexample to the converse appears below.

∎

Four estimators of μ\mu illustrate all combinations, with N(μ,σ2)\Normal(\mu, \sigma^2) data:

EstimatorBiasVarianceConsistent?
Xˉn\bar X_n00σ2/n→0\sigma^2/n \to 0yes
X1X_1 (first observation only)00σ2\sigma^2, does not tend to 0no
∑iXi/(n+10)\sum_i X_i/(n+10)−10μ/(n+10)→0-10\mu/(n+10) \to 0nσ2/(n+10)2→0n\sigma^2/(n+10)^2 \to 0yes, though biased
mean of first ⌈n⌉\lceil\sqrt n\rceil observations00σ2/⌈n⌉→0\sigma^2/\lceil\sqrt n\rceil \to 0yes, but very slowly
InteractiveThe consistency funnel
Funnel of TnT_n and band μ±ε\mu \pm \varepsilon (300 replicates)
μ = 3
  • funnel (5th to 95th percentiles)
  • band μ±ε\mu \pm \varepsilon
  • trajectory inside
  • outside
Fraction of replicates with ∣Tn−μ∣>ε|T_n - \mu| > \varepsilon
  • mean
  • only X₁
  • Σ/(n+10)
  • mean of ⌈√n⌉
  • exact theory for selected estimator
Estimator of μ\mu
0.50
n = 1
Sample size nn1
Replicates outside μ±ε\mu \pm \varepsilon (mean)80.7 %
Same quantity, exact theory80.3 %
Bias | standard deviation0.196 | 1.998
MSE4.015
Consistent?yes: unbiased and consistent
The 300 replicates share data, and each estimator is calculated on the same samples. The colored band is the funnel (replicate 5th and 95th percentiles), thin lines are 24 trajectories, and green band is μ±ε\mu \pm \varepsilon. Right: fraction of replicates outside the band versus nn, tending to zero only for consistent estimators. Play each estimator's animation. Where is the funnel of ∑Xi/(n+10)\sum X_i/(n+10) centered at small nn, and what happens as nn grows? How long does the funnel of Xˉ⌈n⌉\bar X_{\lceil\sqrt n\rceil} take to enter the band compared with the mean's? Narrow the band with ε\varepsilon and compare with the exact curve (dashed).

With ε=0.5\varepsilon = 0.5 and σ=2\sigma = 2, estimator X1X_1 has fixed probability 2(1−Φ(0.25))=0.802(1 - \Phi(0.25)) = 0.80 of falling outside the band for every nn: unbiased but never converging. For the mean this is 2(1−Φ(εn/σ))2\big(1 - \Phi(\varepsilon\sqrt n/\sigma)\big), falling from 43 %43\,\% at n=10n = 10 to 1.2 %1.2\,\% at n=100n = 100. And ∑iXi/(n+10)\sum_i X_i/(n+10) is initially worse than the mean (its center is μn/(n+10)\mu n/(n+10), far from μ=3\mu = 3 for small nn), but catches up as bias dissolves.

Two observations on what consistency does not mean.

It says nothing about speed. Consistency of Xˉ⌈n⌉\bar X_{\lceil\sqrt n\rceil} is true and almost useless: typical error ε\eps needs ⌈n⌉≈(σ/ε)2\lceil\sqrt n\rceil \approx (\sigma/\eps)^2, or n≈(σ/ε)4n \approx (\sigma/\eps)^4 observations instead of (σ/ε)2(\sigma/\eps)^2. Error rate and limiting shape are studied in asymptotic theory with the CLT.

It does not imply bias tends to zero. Let YnY_n be independent of the data with Yn=nY_n = n with probability 1/n1/n and Yn=0Y_n = 0 otherwise. Then Tn=Xˉn+YnT_n = \bar X_n + Y_n is consistent (because P(Yn≠0)=1/n→0\Pr(Y_n \ne 0) = 1/n \to 0), but E[Tn]=μ+1\E[T_n] = \mu + 1 for every nn: bias is always 11 and MSE grows as nn. Rare events with huge consequences move expectation without moving probability. (With uniform integrability, consistency does imply asymptotically zero bias.)

How to prove an estimator consistent

There are two paths. First, the criterion above: calculate bias and variance. Second, the law of large numbers combined with continuity.

Thus Sn2S_n^2 is consistent for σ2\sigma^2 without calculating its variance: 1n∑i(Xi−Xˉ)2=m^2−m^12→Pm2−m12=σ2\frac{1}{n}\sum_i (X_i - \bar X)^2 = \hat m_2 - \hat m_1^2 \xrightarrow{\Pr} m_2 - m_1^2 = \sigma^2 by continuity of (a,b)↦b−a2(a, b) \mapsto b - a^2, and factor n/(n−1)n/(n-1) tends to 11. Only a finite second moment is needed (not the fourth, which calculating Var⁡(S2)\Var(S^2) would require). And SS is consistent for σ\sigma, though biased, by continuity of square root. Consistency is therefore the “cheap” property satisfied by almost any reasonable estimator.

Consistency also fails in pathological cases. If XiX_i are Cauchy, sample mean Xˉn\bar X_n has the same distribution as X1X_1 for every nn (Cauchy is stable) and converges to nothing, although sample median is consistent for the center. This connects to the next section.

Relative efficiency

Between two consistent estimators, which is better? If both are well centered, the one with less variance.

The asymptotic version has a practical reading: to match error, T2T_2 needs ARE⁡(T1,T2)\operatorname{ARE}(T_1, T_2) times the data used by T1T_1. Under normality ARE⁡(mediana,media)=2/π\operatorname{ARE}(\text{mediana}, \text{media}) = 2/\pi, so the median needs π/2≈1.57\pi/2 \approx 1.57 times the mean’s data, 57 %57\,\% more, for equal precision.

The limiting variances we need are classical (M-estimator theory proves them; here we use and simulate them). If data have density ff symmetric about μ\mu, continuous and positive at μ\mu, and finite variance σ2\sigma^2 (the last is only needed for the mean):

vmedia=σ2,vmediana=14f(μ)2.v_{\text{media}} = \sigma^2, \qquad v_{\text{mediana}} = \frac{1}{4f(\mu)^2}.

For normal, f(μ)=1/2πσ2f(\mu) = 1/\sqrt{2\pi\sigma^2} and vmediana=π2σ2v_{\text{mediana}} = \tfrac{\pi}{2}\sigma^2: efficiency of median relative to mean is 2/π=0.6372/\pi = 0.637. For Laplace with scale bb, f(μ)=1/(2b)f(\mu) = 1/(2b), vmediana=b2v_{\text{mediana}} = b^2 and σ2=2b2\sigma^2 = 2b^2: median is twice as efficient as mean (it is the maximum-likelihood estimator in that family). For Student’s tt with ν>2\nu > 2 degrees of freedom,

ARE⁡(mediana,media)=νν−2⋅4fν(0)2,fν(0)=Γ(ν+12)νπ Γ(ν2),\operatorname{ARE}(\text{mediana}, \text{media}) = \frac{\nu}{\nu - 2}\cdot 4f_\nu(0)^2, \qquad f_\nu(0) = \frac{\Gamma\big(\tfrac{\nu+1}{2}\big)}{\sqrt{\nu\pi}\,\Gamma\big(\tfrac{\nu}{2}\big)},

and the mean loses everything when ν≤2\nu \le 2, because its variance is infinite.

The trimmed mean with proportion α\alpha is the natural compromise: α=0\alpha = 0 is mean and α→1/2\alpha \to 1/2 is median. For a symmetric law with quantile ξ=F−1(1−α)\xi = F^{-1}(1 - \alpha), its asymptotic variance is [∫−ξξx2f(x)  ⁣dx+2αξ2]/(1−2α)2\big[\int_{-\xi}^{\xi} x^2 f(x)\,\dd x + 2\alpha\xi^2\big]/(1 - 2\alpha)^2 (the numerator is variance of “winsorized” data: extremes replaced by ±ξ\pm\xi).

InteractiveMean or median: the tail decides
Asymptotic relative efficiency versus mean: Var⁡as(Xˉ) / Var⁡as(T)\Var_{\mathrm{as}}(\bar X)\,/\,\Var_{\mathrm{as}}(T)
mean: infinite variancemean = 1ν ≈ 4.68ν ≈ 10.4
  • mean
  • median
  • 20 % trimmed mean
Estimation errors with n=60n = 60 observations t3.98t_{3.98} (1500 replicates)
  • mean
  • median
  • trimmed
  • truth
3.98
20 % per side
60
Datat3.98t_{3.98}
Best asymptotically among the three20 % trimmed mean
Median efficiency versus mean1.130
Trimmed mean efficiency (20 %) versus mean1.422
Simulated n Var⁡n\,\Var: mean | median | trimmed2.00 | 1.73 | 1.45
Asymptotic n Var⁡n\,\Var: mean | median | trimmed2.01 | 1.78 | 1.41
Data tνt_\nu with ν\nu degrees of freedom: from Cauchy (ν=1\nu = 1) to normal (ν→∞\nu \to \infty). Left: exact asymptotic efficiencies relative to mean (calculated by numerical integration) and crossings with line 11, where mean ties. Right: simulated sampling distributions of the three estimators with nn observations. Start at ν≈4\nu \approx 4: median already beats mean. Raise ν\nu and locate the crossover. Then raise trimming to 45 %45\,\%: trimmed mean converges toward median. For which ν\nu and α\alpha does trimming lose least relative to the better extreme?

Figures (asymptotic, exact):

ν\nuvmediav_{\text{media}}vmedianav_{\text{mediana}}vrecortada 20%v_{\text{recortada }20\%}best
1 (Cauchy)∞\infty2.4672.872median
2∞\infty2.0001.767trimmed
33.0001.8511.520trimmed
51.6671.7351.353trimmed
101.2501.6511.243trimmed (narrowly)
301.0711.5971.176mean
∞\infty (normal)1.0001.5711.145mean

Median beats mean when ν<4.68\nu < 4.68; 20 %20\,\% trimmed mean beats mean when ν<10.4\nu < 10.4. For normal, trimmed retains 87 %87\,\% of mean efficiency (1/1.1451/1.145), a small price for strong protection from outliers (the first lesson’s robust measures). For Cauchy, 20 %20\,\% trimming loses to median: with tails this heavy, trim almost everything.

The method of moments

So far we evaluated estimators given to us. How do we construct one when the model is {Pθ}\{P_\theta\} and θ\theta is not simply a mean? The oldest idea matches model predictions to observations.

Model moments are parameter functions: mk(θ)=Eθ[Xk]m_k(\theta) = \E_\theta[X^k], k=1,2,…k = 1, 2, \dots. Sample moments are m^k=1n∑iXik\hat m_k = \frac{1}{n}\sum_i X_i^k, estimating the former (consistently by the law of large numbers).

Three explicit examples

Gamma. Let Xi∼iidGamma⁡(α,β)X_i \iid \operatorname{Gamma}(\alpha, \beta) (shape α\alpha, rate β\beta; exponential-gamma family). The first two moments are E[X]=α/β\E[X] = \alpha/\beta and Var⁡(X)=α/β2\Var(X) = \alpha/\beta^2. With Xˉ\bar X and V^=1n∑i(Xi−Xˉ)2\hat V = \frac{1}{n}\sum_i (X_i - \bar X)^2 (second central moment, divisor nn), matching gives

α^=Xˉ2V^,β^=XˉV^.\hat\alpha = \frac{\bar X^2}{\hat V}, \qquad \hat\beta = \frac{\bar X}{\hat V}.

Beta. Let Xi∼iidBeta⁡(a,b)X_i \iid \operatorname{Beta}(a, b) (beta), with mean μ=a/(a+b)\mu = a/(a+b) and variance μ(1−μ)/(a+b+1)\mu(1-\mu)/(a+b+1). Solving gives

s^=Xˉ(1−Xˉ)V^−1,a^=Xˉ s^,b^=(1−Xˉ) s^,\hat s = \frac{\bar X(1 - \bar X)}{\hat V} - 1, \qquad \hat a = \bar X\,\hat s, \qquad \hat b = (1 - \bar X)\,\hat s,

with s^\hat s estimating a+ba + b. For (a^,b^)(\hat a, \hat b) to be valid parameters requires s^>0\hat s > 0, or V^<Xˉ(1−Xˉ)\hat V < \bar X(1 - \bar X). With data in (0,1)(0, 1) and divisor nn this always holds because x2<xx^2 < x implies V^=x2‾−xˉ2<xˉ−xˉ2\hat V = \overline{x^2} - \bar x^2 < \bar x - \bar x^2. With divisor n−1n - 1 (used by S2S^2 and many packages by default) it can fail: for 0.010.01 and 0.990.99, S2=0.4802>0.25=xˉ(1−xˉ)S^2 = 0.4802 > 0.25 = \bar x(1 - \bar x) and “parameters” become negative. A divisor detail leaves the estimator undefined.

Uniform. Let Xi∼iidUnif⁡(0,θ)X_i \iid \Unif(0, \theta). The first moment is θ/2\theta/2, so θ^MoM=2Xˉ\hat\theta_{\text{MoM}} = 2\bar X. It is the simplest example and, as we shall see, teaches the most about the method’s limitations.

Consistency

Proof

By the weak law, m^k→Pmk(θ0)\hat m_k \xrightarrow{\Pr} m_k(\theta_0) for each kk, and componentwise convergence in probability is equivalent to vector convergence. By continuous mapping, h(m^1,…,m^p)→Ph(m1(θ0),…,mp(θ0))=θ0h(\hat m_1, \dots, \hat m_p) \xrightarrow{\Pr} h(m_1(\theta_0), \dots, m_p(\theta_0)) = \theta_0.

∎

This four-line proof explains the method’s attraction: it almost always gives a consistent estimator. But consistency is all it guarantees.

Limits of the method

  1. It can leave parameter space. This occurs with divisor n−1n-1 for beta, and with uniform, shown next.
  2. It needs moments. If E∣X∣k=∞\E\abs{X}^k = \infty (heavy-tailed Pareto, Cauchy) sample moments do not converge and the method does not exist.
  3. Moment choice is not unique. For Pois⁡(λ)\Pois(\lambda) both mean and variance are λ\lambda: λ^=Xˉ\hat\lambda = \bar X and λ^=V^\hat\lambda = \hat V are different moment estimators of the same parameter. The lowest order is usually used, but this is a convention, not a theorem. With more moment conditions than parameters, generalized method of moments (GMM) combines them with optimal weights; see econometrics (m27).
  4. It is not efficient. For gamma shape, asymptotic variance of α^MoM\hat\alpha_{\text{MoM}} is 2α(α+1)/n2\alpha(\alpha + 1)/n (calculation with the delta method in lesson 8); with α=3\alpha = 3 it is 24/n24/n. The next lesson’s maximum-likelihood estimator achieves 1/((ψ′(α)−1/α) n)=16.2/n1/((\psi'(\alpha) - 1/\alpha)\,n) = 16.2/n, and for small shapes the difference is huge: with α=0.5\alpha = 0.5 moments have only 23 %23\,\% efficiency relative to likelihood.

The next interactive shows the first limitation in its most striking form (uniform).

InteractiveMethod of moments out of range
A sample of n=8n = 8 points from Unif⁡(0,1)\Unif(0, 1) and three estimates of θ\theta
θmaxcorrected2X̄: impossibleimpossible θ
Sampling distribution of estimators with n=8n = 8 (3000 samples)
  • 2Xˉ2\bar X (moments)
  • maximum
  • corrected maximum
  • truth θ\theta
Probability of an impossible estimate, P(2Xˉ<X(n))\Pr(2\bar X < X_{(n)})
limit 1/2n = 2: never (X₁ + X₂ ≥ max)
8
Histogram scale
This sample: max | 2Xˉ2\bar X | corrected0.824 | 0.728 | 0.927
Is 2Xˉ2\bar X compatible with the data?no, it is < max
Simulated P(2Xˉ<X(n))\Pr(2\bar X < X_{(n)}), 3000 samples26.0 % ± 0.8
MSE of 2Xˉ2\bar X (simulated | exact θ2/(3n)\theta^2/(3n))0.04052 | 0.04167
Corrected MSE (simulated | exact θ2/(n(n+2))\theta^2/(n(n+2)))0.01243 | 0.01250
MSE ratio (theory: (n+2)/3(n+2)/3)3.26 (3.33)
Data Unif⁡(0,1)\Unif(0, 1) (so θ=1\theta = 1). Top: one sample; any θ\theta below the observed maximum is impossible (red region), and estimate 2Xˉ2\bar X sometimes falls inside it. Bottom left: sampling distributions of 2Xˉ2\bar X, maximum, and corrected maximum n+1nX(n)\frac{n+1}{n}X_{(n)} across 3000 samples. Bottom right: probability 2Xˉ2\bar X is impossible versus nn. The initial sample already has an impossible estimate; press 'Another sample' to see frequency. Increase nn: does probability tend to zero? Switch to narrow scale to see the maximum.

Exact facts for θ=1\theta = 1 (maximum X(n)∼Beta⁡(n,1)X_{(n)} \sim \operatorname{Beta}(n, 1) by order statistics):

  • 2Xˉ2\bar X is unbiased with Var⁡=θ2/(3n)\Var = \theta^2/(3n).
  • Maximum has E[X(n)]=nn+1θ\E[X_{(n)}] = \frac{n}{n+1}\theta and Var⁡=nθ2(n+1)2(n+2)\Var = \frac{n\theta^2}{(n+1)^2(n+2)}: downward biased but MSE 2θ2(n+1)(n+2)\frac{2\theta^2}{(n+1)(n+2)}.
  • Corrected maximum n+1nX(n)\frac{n+1}{n}X_{(n)} is unbiased with Var⁡=θ2n(n+2)\Var = \frac{\theta^2}{n(n+2)}.

The MSE ratio between 2Xˉ2\bar X and corrected maximum is (n+2)/3(n+2)/3: at n=10n = 10 the correction is 4 times better, at n=100n = 100 it is 34 times better. Moment-method error decreases as 1/n1/n and maximum error as 1/n21/n^2.

Probability of an impossible estimate, P(2Xˉ<X(n))\Pr(2\bar X < X_{(n)}), is zero for n=2n = 2 (because X1+X2≥max⁡(X1,X2)X_1 + X_2 \ge \max(X_1, X_2) for positive data), 0.280.28 for n=10n = 10, and… tends to 1/21/2:

Proof

Write P(2Xˉ<X(n))=P(Dn<0)\Pr(2\bar X < X_{(n)}) = \Pr(D_n < 0) with Dn=n(2Xˉ−θ)−n(X(n)−θ)D_n = \sqrt{n}(2\bar X - \theta) - \sqrt{n}(X_{(n)} - \theta). By the CLT, n(2Xˉ−θ)→dN(0,θ2/3)\sqrt{n}(2\bar X - \theta) \xrightarrow{d} \Normal(0, \theta^2/3). Meanwhile θ−X(n)≥0\theta - X_{(n)} \ge 0 has mean θ/(n+1)\theta/(n+1), so by Markov P(n(θ−X(n))>ε)≤n θ/((n+1)ε)→0\Pr\big(\sqrt{n}(\theta - X_{(n)}) > \eps\big) \le \sqrt{n}\,\theta/((n+1)\eps) \to 0, or n(X(n)−θ)→P0\sqrt{n}(X_{(n)} - \theta) \xrightarrow{\Pr} 0. By Slutsky’s lemma, Dn→dN(0,θ2/3)D_n \xrightarrow{d} \Normal(0, \theta^2/3). Since the limiting law is continuous at 00, P(Dn<0)→P(N(0,θ2/3)<0)=1/2\Pr(D_n < 0) \to \Pr(\Normal(0, \theta^2/3) < 0) = 1/2.

∎

The underlying reason is scale: error of 2Xˉ2\bar X is order n−1/2n^{-1/2} and maximum error order n−1n^{-1}. Nearly all fluctuation is in 2Xˉ2\bar X, and it is symmetric, so half the time it falls left of a maximum already close to θ\theta. The estimator ignores information that all observations are below θ\theta. This information, summarized in the maximum, is a sufficient statistic, and the estimator using it is maximum likelihood: concepts from lessons 5 and 7.

Simulation studies

Exact bias, variance, and MSE are rarely calculable. They are for a normal sample mean or variance, but not for median of a tt with 5 degrees of freedom, an M-estimator, or a neural network. The general tool is simulation: generate many samples from a known mechanism, apply the procedure to each, and summarize errors. Carelessly done it produces many false literature claims; methodically done it is a research tool.

The now-standard structure is ADEMP (Morris, White, and Crowther, 2019), five questions to answer before running anything:

LetterQuestionIn this lesson
AimsWhat do you want to know?Which center estimator loses least under heavy tails?
Data-generating mechanismsWhat data test it? Several, not onenormal, Laplace, t3t_3; multiple nn
EstimandsWhat exactly is estimated?symmetry center μ=0\mu = 0
MethodsWhich procedures are compared?mean, median, trimmed
Performance measuresHow are they judged?bias, empirical variance, MSE, coverage

An ADEMP simulation study is also an experiment: it has error. Each performance measure averages RR replicates and has Monte Carlo error to report:

MeasureEstimateMonte Carlo error
biasT‾−ψ\overline{T} - \psiV^T/R\sqrt{\hat V_T/R}, with V^T\hat V_T empirical variance of estimates
varianceV^T\hat V_T≈V^T2/(R−1)\approx \hat V_T\sqrt{2/(R-1)} if TrT_r are normal (otherwise, use empirical fourth moment)
MSE1R∑r(Tr−ψ)2\frac{1}{R}\sum_r (T_r - \psi)^2standard deviation of (Tr−ψ)2(T_r - \psi)^2 divided by R\sqrt{R}
interval coverageproportion p^\hat p of replicates coveringp^(1−p^)/R\sqrt{\hat p(1 - \hat p)/R}

The bias formula gives a rule for choosing RR: for Monte Carlo error δ\delta in bias of an estimator with standard deviation σT\sigma_T, R=(σT/δ)2R = (\sigma_T/\delta)^2 replicates are needed. For a 95 %95\,\% interval’s coverage with Monte Carlo error 0.5 %0.5\,\%, R=0.95⋅0.05/0.0052=1900R = 0.95 \cdot 0.05/0.005^2 = 1900. Error decreases only as R−1/2R^{-1/2}: halving it costs four times as many replicates.

Four good habits:

  • Reproducible seeds and generators, so anyone can reproduce your table bit for bit (numpy.random.Generator with explicit seed).
  • Common random numbers: all methods see the same samples. Then the difference between methods has much less noise than each separately.
  • Multiple data mechanisms, including those unfavorable to your method. A proposed method tested only where it excels proves nothing.
  • Count failures (nonconvergence, out-of-range estimates) instead of discarding them, and report each figure’s Monte Carlo error.

Implementation from scratch

Before the general framework, directly check decomposition with three divisors: bias, variance, and MSE of SS⁡/d\operatorname{SS}/d, using 200 000200\,000 standard normal samples of size n=10n = 10, compared with exact theorem values.

[ ]Bias, variance, and MSE of sample varianceBrowser
import numpy as np

rng = np.random.default_rng(0)
n, R = 10, 200_000
X = rng.normal(0.0, 1.0, size=(R, n))                 # sigma^2 = 1
SS = ((X - X.mean(axis=1, keepdims=True)) ** 2).sum(axis=1)

print(f"{'divisor':>8} {'sesgo':>8} {'varianza':>9} {'sesgo²+var':>11} {'ECM':>8} {'ECM exacto':>11}")
for nombre, d in [("n-1", n - 1), ("n", n), ("n+1", n + 1)]:
    est = SS / d
    sesgo = est.mean() - 1.0
    var = est.var(ddof=1)
    ecm = ((est - 1.0) ** 2).mean()
    c = (n - 1) / d
    exacto = (c - 1) ** 2 + 2 * (n - 1) / d**2
    print(f"{nombre:>8} {sesgo:8.4f} {var:9.4f} {sesgo**2 + var:11.4f} {ecm:8.4f} {exacto:11.4f}")

Columns “bias² + variance” and “MSE” agree to four digits: decomposition is an algebraic fact, not an approximation (the small difference between variance with divisor R−1R - 1 and MSE with divisor RR appears only in the fifth). Simulated MSE also agrees with exact up to Monte Carlo error.

Now the general framework. It is deliberately small, four pieces corresponding to ADEMP letters. A mechanism (D and E) can generate a data block of shape (R,n)(R, n) and knows the true estimand; a method (M) receives the block and returns each replicate’s estimate and optionally standard error; function resumen (P) calculates measures with Monte Carlo error; and simular makes all methods see exactly the same samples.

[ ]An ADEMP framework from scratchBrowser
import zlib
import numpy as np
from scipy import stats

def _rng(semilla, *claves):
    """Un generador por (semilla, n, mecanismo): reproducible e independiente de R y del orden."""
    return np.random.default_rng([semilla, *claves])

class Mecanismo:
    """D y E de ADEMP: cómo se generan los datos y qué se estima."""
    def __init__(self, nombre, muestrear, estimando):
        self.nombre, self.muestrear, self.estimando = nombre, muestrear, estimando

def resumen(est, se=None, theta=0.0, z=1.96):
    """P de ADEMP: sesgo, varianza empírica, ECM y cobertura, cada uno con su error Monte Carlo."""
    est = np.asarray(est, dtype=float)
    R = len(est)
    err = est - theta
    var = est.var(ddof=1)
    m4 = ((est - est.mean()) ** 4).mean()
    out = dict(
        sesgo=err.mean(), ee_sesgo=np.sqrt(var / R),
        var=var, ee_var=np.sqrt(max(m4 - var**2 * (R - 3) / (R - 1), 0.0) / R),
        ecm=(err**2).mean(), ee_ecm=(err**2).std(ddof=1) / np.sqrt(R),
        cob=np.nan, ee_cob=np.nan,
    )
    if se is not None:
        cob = np.mean(np.abs(err) <= z * se)
        out.update(cob=cob, ee_cob=np.sqrt(cob * (1 - cob) / R))
    return out

def simular(mec, metodos, n, R, semilla=2024):
    """M de ADEMP: todos los métodos ven las MISMAS R muestras (números aleatorios comunes)."""
    x = mec.muestrear(_rng(semilla, n, zlib.crc32(mec.nombre.encode())), (R, n))
    res = {}
    for nombre, f in metodos.items():
        salida = f(x)
        est, se = salida if isinstance(salida, tuple) else (salida, None)
        res[nombre] = (np.asarray(est), se)
    return res

def tabla(mec, res):
    for nombre, (est, se) in res.items():
        r = resumen(est, se, mec.estimando)
        cob = "     -" if np.isnan(r["cob"]) else f"{100 * r['cob']:5.1f}%"
        print(f"{mec.nombre:>8} {nombre:>10}  sesgo {r['sesgo']:+.4f} ({r['ee_sesgo']:.4f})  "
              f"var {r['var']:.4f} ({r['ee_var']:.4f})  ECM {r['ecm']:.4f} ({r['ee_ecm']:.4f})  cob {cob}")

# métodos para estimar el centro de una ley simétrica
def media(x):
    return x.mean(axis=1), x.std(axis=1, ddof=1) / np.sqrt(x.shape[1])

def mediana(x):
    # error estándar «de manual» (válido solo bajo normalidad): sqrt(pi/2) * s / sqrt(n)
    return np.median(x, axis=1), 1.2533 * x.std(axis=1, ddof=1) / np.sqrt(x.shape[1])

def recortada(x):
    return stats.trim_mean(x, 0.2, axis=1)

METODOS = {"media": media, "mediana": mediana, "recort.20%": recortada}
MECANISMOS = [   # las tres leyes tienen varianza 1 y centro 0
    Mecanismo("normal", lambda g, s: g.standard_normal(s), 0.0),
    Mecanismo("laplace", lambda g, s: g.laplace(0, 1 / np.sqrt(2), s), 0.0),
    Mecanismo("t3", lambda g, s: g.standard_t(3, s) / np.sqrt(3), 0.0),
]

n, R = 20, 4000
for mec in MECANISMOS:
    tabla(mec, simular(mec, METODOS, n, R))

Read the table as a research result, with Monte Carlo errors in parentheses. Under normality mean MSE is 0.05000.0500 (exact: 1/201/20), median 0.07350.0735, and trimmed mean between; under Laplace and t3t_3 the order changes: median and trimmed win, with trimmed best for t3t_3. Differences are several times their Monte Carlo errors, not noise. Two subtler points. First, all biases are compatible with zero (within a couple of Monte Carlo errors), as expected for a symmetry center. Second, mean coverage is 93.3 %93.3\,\% with Monte Carlo error around 0.40.4 points: it misses nominal 95 %95\,\% and the difference is not noise; z=1.96z = 1.96 ignores that SS is estimated (at n=20n = 20 use a t19t_{19} quantile, 2.092.09; interval lessons develop this). Median overcovers under Laplace and t3t_3 (98 %98\,\%) because its “textbook” standard error is designed for normality: coverage evaluates the pair (estimator, standard error), not estimator alone.

Monte Carlo error and common random numbers are clearer in two further experiments with the same framework: difference in MSE between median and mean measured paired and unpaired, and how error shrinks with RR.

[ ]Common random numbers and Monte Carlo error versus RBrowser
# Números aleatorios comunes: la diferencia de ECM entre dos métodos se mide mucho mejor emparejando
mec = MECANISMOS[0]
res = simular(mec, METODOS, n, R)
a, b = res["media"][0], res["mediana"][0]
d = (b - mec.estimando) ** 2 - (a - mec.estimando) ** 2        # ECM(mediana) - ECM(media), réplica a réplica
ee_pareado = d.std(ddof=1) / np.sqrt(R)
ee_indep = np.sqrt(((a - 0) ** 2).std(ddof=1) ** 2 / R + ((b - 0) ** 2).std(ddof=1) ** 2 / R)
print(f"normal, n={n}: ECM(mediana) - ECM(media) = {d.mean():.4f}")
print(f"  error Monte Carlo emparejado:    {ee_pareado:.4f}")
print(f"  error Monte Carlo sin emparejar: {ee_indep:.4f}")
print(f"  teoría asintótica: (pi/2 - 1)/n = {(np.pi / 2 - 1) / n:.4f}")

# El error Monte Carlo baja como 1/sqrt(R): ECM de la media bajo la normal, exacto = 1/n
print("\nR      ECM estimado ± EE     (exacto 1/n = %.4f)" % (1 / n))
for R_ in (100, 1000, 10_000, 100_000):
    est = simular(mec, {"media": media}, n, R_)["media"][0]
    r = resumen(est, None, 0.0)
    print(f"{R_:>6}   {r['ecm']:.4f} ± {r['ee_ecm']:.4f}")

Pairing reduces Monte Carlo error of the difference (from 0.00200.0020 to 0.00120.0012) because mean and median use the same samples and their errors are strongly correlated. The last table’s error falls as R−1/2R^{-1/2}: at R=100R = 100 the interval of ±2\pm 2 Monte Carlo errors spans 0.0400.040 to 0.0740.074 (±30 %\pm 30\,\% of the value), while at R=105R = 10^5 it is below ±1 %\pm 1\,\%. Asymptotic difference (π/2−1)/n=0.0285(\pi/2 - 1)/n = 0.0285 is somewhat larger than at n=20n = 20 (0.02350.0235): n=20n = 20 is not yet asymptotic, another reason to simulate instead of trusting the limit.

With libraries

scipy.stats already implements moment fitting for each distribution: rv_continuous.fit(datos, method="MM"). Fix parameters not being estimated, because scipy’s gamma has three parameters (shape, location, scale) and the method uses as many moments as free parameters. With floc=0 (and fscale=1 for beta) this becomes the lesson’s two-parameter case. Compare our formulas with the library.

[ ]Gamma and beta MoM: custom versus scipyBrowser
def mom_gamma(x):
    """Gamma(forma a, tasa b) por momentos; x tiene forma (..., n)."""
    m = x.mean(axis=-1)
    v = x.var(axis=-1)                  # segundo momento central: divisor n
    return m**2 / v, m / v

def mom_beta(x):
    m = x.mean(axis=-1)
    v = x.var(axis=-1)
    s = m * (1 - m) / v - 1             # a + b
    return m * s, (1 - m) * s

rng = np.random.default_rng(7)
xg = rng.gamma(shape=3.0, scale=2.0, size=500)          # a = 3, b = 1/2
a, b = mom_gamma(xg)
ah, loc, esc = stats.gamma.fit(xg, floc=0, method="MM")
print(f"gamma  propio: a = {a:.6f}, b = {b:.6f}")
print(f"gamma  scipy:  a = {ah:.6f}, b = {1 / esc:.6f}   (scale = {esc:.6f})")

xb = rng.beta(2.0, 5.0, size=500)
a, b = mom_beta(xb)
ah, bh, _, _ = stats.beta.fit(xb, floc=0, fscale=1, method="MM")
print(f"beta   propio: a = {a:.6f}, b = {b:.6f}")
print(f"beta   scipy:  a = {ah:.6f}, b = {bh:.6f}")

Gamma agrees to all displayed digits; beta to four decimal places (the library numerically solves what we rearranged by hand, and scipy gamma parameterizes with scale 1/β1/\beta). With these and ADEMP, the natural question is moment-method error as a function of nn:

[ ]MSE of gamma shape moment estimatorBrowser
# ECM del estimador por momentos de la forma de una gamma(3, tasa 1/2) en función de n
alfa, R = 3.0, 2000
print(f"{'n':>5} {'sesgo':>8} {'ECM':>8} {'n*ECM':>8}   (2a(a+1) = {2 * alfa * (alfa + 1):.0f})")
for n in (10, 30, 100, 300, 1000):
    x = np.random.default_rng([11, n]).gamma(alfa, 2.0, size=(R, n))
    ah, _ = mom_gamma(x)
    r = resumen(ah, None, alfa)
    print(f"{n:>5} {r['sesgo']:+8.3f} {r['ecm']:8.3f} {n * r['ecm']:8.1f}")

Three readings. Bias is positive and large for small nn (+1.4+1.4 at n=10n = 10, 48 %48\,\% of true value 33): gamma shape’s moment estimator overestimates, giving MSE 8.98.9 at n=10n = 10. Still it is consistent: bias falls as 1/n1/n and so does MSE. Product n⋅ECM⁡n\cdot\operatorname{ECM} stabilizes around 2424 as nn grows, the asymptotic variance value 2α(α+1)=242\alpha(\alpha + 1) = 24. Simulation confirms the delta-method calculation you have not yet done.

Finally, a preview of next lesson: the same shape’s maximum-likelihood estimator, with the same nn and comparison framework.

[ ]Preview: moments versus likelihoodBrowser
# Un adelanto de la lección siguiente: la máxima verosimilitud para la misma forma
n, R = 100, 150
x = np.random.default_rng([5, n]).gamma(alfa, 2.0, size=(R, n))
mm = mom_gamma(x)[0]
ml = np.array([stats.gamma.fit(f, floc=0)[0] for f in x])
print(f"n = {n}, {R} réplicas, forma verdadera {alfa}")
print(f"  momentos:        ECM = {np.mean((mm - alfa) ** 2):.3f}")
print(f"  verosimilitud:   ECM = {np.mean((ml - alfa) ** 2):.3f}")

With only 150 replicates the result is indicative (Monte Carlo error is order 12 %12\,\% of MSE) but agrees with asymptotic theory: 24/100=0.2424/100 = 0.24 for moments and 16.2/100=0.1616.2/100 = 0.16 for likelihood.

Common mistakes

Exercises

ProofMSE decomposition and sample variance
Prove: If TT has finite second moment, ECM⁡(T)=sesgo⁡(T)2+Var⁡(T)\operatorname{ECM}(T) = \operatorname{sesgo}(T)^2 + \Var(T). If Xi∼iidPX_i \iid P has mean μ\mu and variance σ2<∞\sigma^2 < \infty, sample variance S2=1n−1∑i(Xi−Xˉ)2S^2 = \frac{1}{n-1}\sum_i (X_i - \bar X)^2 is unbiased for σ2\sigma^2.
0
Write ψ\psi for the estimand and m=E[T]m = \E[T].

Step 1 of 4. How do you start the decomposition?

NumericOptimal divisor for n = 10
For X1,…,Xn∼iidN(μ,σ2)X_1, \dots, X_n \iid \Normal(\mu, \sigma^2), the constant cc minimizing MSE of c∑i(Xi−Xˉ)2c\sum_i (X_i - \bar X)^2 as an estimator of σ2\sigma^2 is c=1/(n+1)c = 1/(n + 1). Evaluate it for n=10n = 10.
NumericMedian asymptotic efficiency under normality
For normal data, calculate median's asymptotic relative efficiency to mean, vmedia/vmedianav_{\text{media}}/v_{\text{mediana}}, knowing vmediana=1/(4f(μ)2)v_{\text{mediana}} = 1/(4f(\mu)^2).
QuizTwo estimators with opposite properties
Two estimator sequences estimate ψ\psi. Sequence AnA_n is unbiased and its variance does not tend to zero. Sequence BnB_n is biased, and its bias and variance tend to zero. Which statements are true?

More than one answer may be correct.

NumericMoments for a gamma
A Gamma⁡(α,β)\operatorname{Gamma}(\alpha, \beta) sample (shape α\alpha, rate β\beta) has sample mean xˉ=6\bar x = 6 and second central moment V^=1n∑i(xi−xˉ)2=9\hat V = \frac{1}{n}\sum_i (x_i - \bar x)^2 = 9. Calculate the moment estimate of rate β\beta.
NumericMoments versus corrected maximum
If X1,…,Xn∼iidUnif⁡(0,θ)X_1, \dots, X_n \iid \Unif(0, \theta), calculate ratio ECM⁡(2Xˉ)/ECM⁡(n+1nX(n))\operatorname{ECM}(2\bar X)/\operatorname{ECM}\big(\tfrac{n+1}{n}X_{(n)}\big) for n=25n = 25.
NumericHow many replicates?
You simulate coverage of a confidence interval at nominal level 0.950.95 and want Monte Carlo error of estimated coverage at most 0.0050.005. What is the minimum number of replicates?
NumericWhen constant 0 beats the unbiased estimator
Observe X∼Pois⁡(λ)X \sim \Pois(\lambda) and estimate e−2λe^{-2\lambda}. The only unbiased estimator is (−1)X(-1)^X with MSE 1−e−4λ1 - e^{-4\lambda}, and constant estimator 00 has MSE e−4λe^{-4\lambda}. Above what λ\lambda does constant 00 have lower MSE than the unbiased estimator?
QuizA simulation that does not hold up
A colleague presents: 'My new estimator has 94 %94\,\% coverage in simulation. I used 100 standard normal replicates with n=30n = 30, without fixing the seed, and did not calculate Monte Carlo errors.' Which criticisms are valid?

More than one answer may be correct.

CodeBeta method-of-moments estimator
Implement mom_beta(x, ddof=0), accepting a 1D sample x from a Beta⁡(a,b)\operatorname{Beta}(a, b) and returning (a_hat, b_hat) by moments: s^=xˉ(1−xˉ)/v−1\hat s = \bar x(1 - \bar x)/v - 1, a^=xˉs^\hat a = \bar x\hat s, b^=(1−xˉ)s^\hat b = (1 - \bar x)\hat s, where v is sample variance with divisor n - ddof. Raise ValueError with a clear message if any value is not strictly in (0,1)(0, 1), variance is 00, or s^≤0\hat s \le 0 (sample moments incompatible with beta). Tests also check consistency in simulation.
import numpy as np

def mom_beta(x, ddof=0):
  """Estimador por momentos de (a, b) de una beta. Devuelve (a_hat, b_hat)."""
  x = np.asarray(x, dtype=float)
  # tu código: valida los datos, calcula media y varianza (divisor n - ddof),
  # s = m (1 - m) / v - 1 y comprueba que s > 0 antes de devolver (m s, (1 - m) s)
  return 1.0, 1.0
Shift+Enter to run

Summary

Key idea
An estimator is a random variable judged by its error distribution: MSE is squared bias plus variance, and minimizing it sometimes requires accepting bias; consistency guarantees enough data eventually give accuracy, and the method of moments is the simplest way to construct consistent, but not best, estimators.
  • Distinguish estimand (unknown number), estimator (random variable), and estimate (observed number). Bias, variance, and consistency describe the estimator.
  • ECM⁡=sesgo⁡2+Var⁡\operatorname{ECM} = \operatorname{sesgo}^2 + \Var. Bessel’s correction makes S2S^2 unbiased, but under normality minimum MSE occurs at biased divisor n+1n + 1: at n=10n = 10, 2/11=0.1818 σ42/11 = 0.1818\,\sigma^4 versus 2/9=0.2222 σ42/9 = 0.2222\,\sigma^4. With heavy tails the optimum divisor is higher, n+1+κ(n−1)/nn + 1 + \kappa(n-1)/n.
  • Consistency (convergence in probability) and unbiasedness are independent. MSE tending to zero suffices for consistency but is not necessary. Consistency says nothing about speed.
  • Relative efficiency depends on tails: under normality median has asymptotic efficiency 2/π≈0.642/\pi \approx 0.64 relative to mean; under Laplace, 2; under tνt_\nu, median wins if ν<4.68\nu < 4.68 and 20 %20\,\% trimmed mean if ν<10.4\nu < 10.4.
  • Method of moments equates population and sample moments and is consistent by the law of large numbers and continuous mapping. It can leave parameter space (uniform: P(2Xˉ<X(n))→1/2\Pr(2\bar X < X_{(n)}) \to 1/2), needs finite moments, and is inefficient (gamma: 24/n24/n versus 16.2/n16.2/n for α=3\alpha = 3).
  • A simulation study uses ADEMP, seeds and common random numbers, multiple mechanisms, and reports Monte Carlo error (V^/R\sqrt{\hat V/R} for bias, p^(1−p^)/R\sqrt{\hat p(1-\hat p)/R} for coverage; R=1900R = 1900 for ±0.5 %\pm 0.5\,\% at 95 %95\,\%).