From first principles
Derive a Monte Carlo estimate and its sampling error
Draw independent, uniformly distributed points \(X_i\) on \([a,b]\), and suppose \(f(X_i)\) has finite variance \(\sigma_f^2\). The expected value of one function sample is its integral divided by the interval length. This immediately gives an unbiased integral estimator,
For independent draws, the variance of a sum is the sum of the variances. Dividing by the square of the sample count gives
Replacing \(\sigma_f\) by the empirical sample standard deviation estimates the standard error. The \(1/\sqrt N\) decrease concerns repeated sampling; it is not a deterministic bound on one estimate. Quadrupling the number of evaluations halves that standard error. Dependence between samples, an infinite variance, or a biased point generator changes the reasoning and the interpretation of the reported uncertainty.
Derivation and applications
Predict when a reflected random sample reduces integration noise
Uniform draws on \([0,1]\) have the same distribution after reflection about \(1/2\). This permits antithetic sampling, in which each independent draw \(U\) is paired with \(1-U\). For a square-integrable integrand \(f\), define the per-pair estimate \(Z\) as the average of its two evaluations. Both terms have the desired integral as their expectation, so
Assume \(m\) independently generated pairs and finite single-sample variance \(\sigma^2>0\). The two members within a pair can be correlated. Let \(\rho\) be their correlation. Expanding the variance of their sum gives
For the same \(2m\) evaluations, independent sampling has variance \(\sigma^2/(2m)\); thus negative correlation helps. The source of any reduction can be seen by decomposing \(f\) about the midpoint into symmetric and antisymmetric pieces,
Pair averaging keeps the first and cancels the second exactly. The two pieces are orthogonal under uniform integration, so cancellation removes the antisymmetric contribution to variability. It also uses two evaluations for each independent pair. Standard errors should therefore be calculated across the pair averages.
Worked example
Calculate the gain for a quadratic integrand
For \(f(x)=x^2\),
The covariance with its reflected partner is \(\int_0^1x^2(1-x)^2dx-1/9=1/30-1/9=-7/90\), giving \(\rho=-7/8\). At a fixed evaluation budget the variance falls by a factor of eight and the standard error by \(\sqrt8\). Each pair integrates the linear part about the midpoint exactly.
Second application
Recognize when the second evaluation is redundant
For \(f(x)=(x-1/2)^2\), reflection gives the same function value. Here \(\rho=1\) and the paired method has twice the variance of independent sampling at equal cost. With 200 evaluations and single-value variance \(1/180\), the independent standard error is \(1/\sqrt{36000}=0.00527\); using 100 independent pairs gives
Turn area into an expectation
For an integrable \(f\) on \([a,b]\), let \(U\) be uniform on the interval. Then \(I=(b-a)\mathbb E[f(U)]\). Independent draws give an unbiased estimator by averaging their function values and multiplying by the length. With finite variance \(\sigma^2=\operatorname{Var}(f(U))\), independence eliminates cross-covariances and gives
The typical size of the sampling error decreases with the square root of the sample count. Multiplying the budget by four halves the standard error.
In a numerical run replace the unknown variance by the sample variance with denominator \(n-1\). For a sufficiently large sample with a suitable distribution, a normal approximation provides an approximate confidence interval. A particular interval need not contain the exact answer. Heavy tails, correlated draws or a nearly unsampled small peak can make the estimated uncertainty unreliable. Recording the random seed reproduces the same sequence of sample values; independent seeds are needed for independent replications.
Four draws and the uncertainty they reveal
For \(f(x)=x\) on \([0,1]\), four illustrative draws at 0.1, 0.2, 0.7 and 0.8 have mean 0.45. Their squared deviations sum to 0.37, yielding sample variance \(0.37/3\) and estimated standard error \(\sqrt{0.37/12}\approx0.176\). The exact integral is 0.5, so the observed error is 0.05. Because the uniform variance is exactly \(1/12\), the true standard deviation for repeated sets of four draws is \(\sqrt{1/48}\approx0.144\). These three numbers answer different questions about this one run and its possible replications.
Guarantee some coverage before sampling
Divide the interval into \(n\) equal strata and draw one independent point uniformly inside each. Sum each sample value times its stratum width. The estimator remains unbiased since each local expectation equals the mean over its stratum. For \(f(x)=x\) every local variance is \(1/(12n^2)\). Multiplying by the squared width and summing \(n\) independent contributions gives a total variance of \(1/(12n^3)\). For four samples the standard deviation drops to about 0.0361. The gain comes from fixing the amount of sampling effort in each region.
A single sample per stratum cannot estimate its own local variance. Independent repetitions of the complete stratified procedure or more samples per stratum permit empirical uncertainty estimates. In high dimension a full Cartesian partition requires rapidly growing numbers of cells. Simple Monte Carlo retains the same square-root rate under finite variance, but the variance constant and the cost of sampling can still depend strongly on dimension. Identify both the estimator and the method used to measure its uncertainty when reporting a numerical integral.
Use a known integral to reduce variability
For \(f(x)=x+x^2\), the integral of the first term is known to be one half. Sampling only \(x^2\) and adding one half leaves the expectation unchanged. The original sample variance per uniform draw is
The residual sample variance per draw is \(1/5-(1/3)^2=4/45\), less than one third as large. This control-variate construction uses a known mean and a correlation with the original integrand. An arbitrary replacement by a superficially similar function without restoring its known mean would bias the estimate.
Sample more often where the integrand is large
For a nonuniform positive probability density \(q\) on the integration region, the identity \(\int f(x)\,dx=\mathbb E_q[f(X)/q(X)]\) holds whenever the sampling distribution covers the integrand's support. Independent samples produce an unbiased estimate. Its variance per draw is \(\int f(x)^2/q(x)\,dx-I^2\), provided this integral is finite. A density concentrated near large contributions can reduce this variance even if generating a nonuniform draw costs little more than generating a uniform one. A density that is too small where the integrand is large can have the opposite effect.
Cauchy–Schwarz applied to \(\int |f|=\int (|f|/\sqrt q)\sqrt q\) gives
Equality requires \(q\) proportional to \(|f|\). For a nonnegative integrand that ideal density makes the sample weight constant and the variance zero. Constructing its normalising constant would generally require knowing the integral itself. The result is thus a design guide: choose a tractable density approximating the shape of the large contributions, with known normalisation and sufficiently broad coverage.
Restore finite variance for an integrable endpoint peak
Take \(f(x)=x^{-1/2}\) on \((0,1]\). The integral is two. Under uniform sampling each weight is finite almost surely and has that finite mean, but its second moment is
The familiar standard-error formula based on a finite variance and a square-root sampling rate is therefore unjustified, even if a modest run happens to avoid tiny \(x\) and reports a reassuringly small sample variance.
Choose \(q(x)=(3/4)x^{-1/4}\). Its cumulative distribution is \(x^{3/4}\), so one draws \(X=U^{4/3}\) for a uniform \(U\). The importance weight is
The second moment is \((4/3)\int_0^1 x^{-3/4}dx=16/3\), giving variance \(16/3-4=4/3\). For 300 independent draws the exact standard deviation of the mean is
This result quantifies an uncertainty that uniform sampling could not express through a finite variance.
For the ideal comparison \(q_\ast=x^{-1/2}/2\), the cumulative distribution is \(\sqrt x\); generating \(X=U^2\) gives \(W=2\) on every draw. Change the integrand to \(x^{-1/2}(1+x)\) while retaining this density and the weights become \(2(1+X)\), bounded between two and four. The method still controls the singular behaviour without needing exact knowledge of the new integral. For a sign-changing integrand, even sampling from \(|f|\) retains sign fluctuation and cannot eliminate cancellation between large positive and negative contributions.
To check the improved density numerically, record both the sample mean and the largest weight across independent replications. A computation that clips extremely small sampled values of \(X\) to avoid a large weight changes the target expectation. Under the proposed \(q\), the omitted integrand area from zero to a cutoff \(\delta\) is \(2\sqrt\delta\). Even a cutoff of \(10^{-4}\) removes 0.02 integral units, which is already thirty percent of the quoted standard error for 300 samples. Tail handling is therefore part of defining the estimator.
A stable implementation can generate the weight directly from the sampled uniform variable and check this omitted-area estimate.
Compute the expected benefit of stratifying a smooth integrand
Estimate \(\int_0^1 x\,dx\) by sampling function values. A uniform draw has variance 1/12; a draw restricted to a stratum of width \(1/N\) has variance \(1/(12N^2)\). Combine \(N\) independent equal-weight draws in each design.

Read values from the plot
| Number of independent uniforms | Independent uniform samples | One point per equal stratum |
|---|---|---|
| 2 | 0.20412 | 0.10206 |
| 8 | 0.10206 | 0.012758 |
| 32 | 0.051031 | 0.0015947 |
| 64 | 0.036084 | 0.00056382 |
| 256 | 0.018042 | 7.0477e−5 |
Change parameters · Compute the expected benefit of stratifying a smooth integrand
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Study the full derivation
Spend random samples where they reduce uncertainty · Function approximation and numerical integration
A Monte Carlo estimate can be unbiased and still too noisy to be useful. Derive control variates, allocate a fixed budget across strata, and distinguish variance reduction from an underestimated standard error.