Tutorials › Statistical Learning (Graduate) › Boundary Bias and Density Corrections

Nonparametric Density Estimation · Tutorial 600 of 989

Boundary Bias and Density Corrections

Derive boundary bias and compare reflection with a normalized one-sided kernel correction, including their assumptions and limitations.

Intermediate 12 min read

What You'll Learn

  • Derive the missing-kernel-mass bias at a compact-support boundary
  • Analyze ordinary kernel bias within a bandwidth of the edge
  • Construct reflection estimators and verify their boundary behavior
  • Normalize a truncated kernel to reproduce a locally constant density
  • Compare the corrections and identify the bias they do not remove

Why the Boundary Changes the Calculation

A symmetric kernel balances observations on the left and right of an evaluation point. Near the edge of a density's support, some of that balance falls outside the region where observations can occur. The ordinary kernel density estimator still assigns weight to those unavailable locations, so its expectation can be far below the true density—even when the density is smooth at the edge.

This is not just a small adjustment to the usual interior bias expansion. Within a bandwidth of the boundary, the fraction of the kernel that lies inside the support can remain substantially below one as the sample size grows and the bandwidth shrinks. Reflection and boundary-kernel methods address that missing mass in different ways.

Setup: Let \(X_1,\ldots,X_n\) be independent observations with density \(f\) supported on \([0,\infty)\). For a bandwidth \(h>0\), the ordinary kernel density estimator is
$$ \hat f_h(x)=\frac{1}{nh}\sum_{i=1}^n K\!\left(\frac{x-X_i}{h}\right). $$
Assume throughout the basic derivations that \(K\) is a nonnegative, symmetric density supported on \([-1,1]\). The same boundary-mass argument applies to other symmetric kernels when the relevant integrals exist.

The Ordinary Estimator Near the Edge

Taking the expectation of the estimator and changing variables to \(u=(x-y)/h\) gives, for \(x\geq 0\),

$$ E[\hat f_h(x)] =\int_0^\infty \frac{1}{h}K\!\left(\frac{x-y}{h}\right)f(y)\,dy =\int_{-\infty}^{x/h}K(u)f(x-hu)\,du. $$

At an interior point, the whole kernel is available when \(h\) is small, and the usual bias expansion uses its full moments. At the boundary \(x=0\), only \(u\leq 0\) contributes. If \(f\) is continuous from the right at zero, the estimator's expectation approaches \(f(0)\int_{-\infty}^0K(u)\,du=f(0)/2\), not \(f(0)\). More generally, at \(x=ch\), for fixed \(c\geq0\), the leading multiplier of \(f(0)\) is \(\int_{-\infty}^cK(u)\,du\). This multiplier is generally less than one when \(c<1\).

Worked Example: A Uniform Kernel at the Boundary

Take \(K(u)=1/2\) for \(-1\leq u\leq1\), zero otherwise, and \(f(x)=e^{-x}\) for \(x\geq0\). This is a density because \(\int_0^\infty e^{-x}\,dx=1\), and its boundary value is \(f(0)=1\). Set \(h=0.2\).

At \(x=0\), the ordinary estimator has expectation

$$ E[\hat f_h(0)] =\frac{1}{2h}\int_0^h e^{-y}\,dy =\frac{1-e^{-h}}{2h} =\frac{1-e^{-0.2}}{0.4} \approx 0.4532. $$

The estimate's expectation is less than half the true boundary density, \(1\). As \(h\) decreases, the displayed expression tends to \(1/2\), not to \(1\). The error is caused by the missing half of the kernel, rather than by a failure of \(f\) to be smooth: here \(f\) is differentiable at zero.

Boundary-layer result: Suppose \(f\) is bounded near zero and continuous from the right at zero, and \(K\) is supported on \([-1,1]\). For any fixed \(c\geq0\), as \(h\downarrow0\),
$$ E[\hat f_h(ch)]\longrightarrow f(0)\int_{-\infty}^{c}K(u)\,du. $$
Proof: Substitute \(x=ch\) in the expectation formula. The integrand is \(K(u)f(h(c-u))\), with \(u\leq c\). Because \(K\) is supported on \([-1,1]\), this integral is over a bounded interval. For each \(u\) in that interval, \(h(c-u)\to0\), so continuity gives \(f(h(c-u))\to f(0)\). Boundedness of \(f\) near zero and integrability of \(K\) provide an integrable bound; dominated convergence therefore gives the stated limit. Symmetry and unit integral imply \(\int_{-\infty}^{0}K(u)\,du=1/2\), yielding the half-density limit at \(c=0\). \(\square\)

Reflection: Add the Missing Mass Back

Reflection treats each observation \(X_i\) as if it were accompanied by a mirror observation at \(-X_i\). For estimation on the nonnegative half-line, the resulting estimator is

$$ \hat f_h^{\,R}(x) =\frac{1}{nh}\sum_{i=1}^n \left[ K\!\left(\frac{x-X_i}{h}\right) +K\!\left(\frac{x+X_i}{h}\right) \right], \qquad x\geq0. $$

The second term supplies kernel weight from the reflected side of the boundary. At zero, symmetry makes the two terms equal, so the expected kernel mass that was missing from the ordinary estimator is restored.

Theorem: Under the boundary-layer result's assumptions, for each fixed \(c\geq0\),
$$ E[\hat f_h^{\,R}(ch)]\longrightarrow f(0) \qquad\text{as }h\downarrow0. $$
Proof: Taking expectations and changing variables in the first term gives
$$ E[\hat f_h^{\,R}(ch)] =\int_{-\infty}^{c}K(u)f(h(c-u))\,du +\int_0^\infty K(c+v)f(hv)\,dv. $$
The second integral follows by putting \(y=hv\) in the expectation of \(K((ch+X_i)/h)\). For fixed \(c\), compact support of \(K\) restricts both integrals to bounded ranges. Continuity and boundedness of \(f\) near zero allow dominated convergence, so their limits are
$$ f(0)\left\{\int_{-\infty}^{c}K(u)\,du +\int_0^\infty K(c+v)\,dv\right\} =f(0)\left\{\int_{-\infty}^{c}K(u)\,du +\int_c^\infty K(w)\,dw\right\} =f(0). $$
The last equality uses the unit integral of \(K\). \(\square\)

Worked Example: Reflection at Zero

Continue with the uniform kernel, exponential density, and \(h=0.2\). At \(x=0\), the two kernel terms in the reflection estimator are equal. Therefore,

$$ E[\hat f_h^{\,R}(0)] =\frac{1}{h}\int_0^h e^{-y}\,dy =\frac{1-e^{-0.2}}{0.2} \approx 0.9063. $$

This is much closer to the true value \(f(0)=1\) than the ordinary estimator's expectation, approximately \(0.4532\). It is not exactly one for this positive bandwidth: reflection restores the leading, constant-density contribution, but the density changes across the interval \([0,h]\).

Reflection also preserves total mass on the half-line. For a fixed observation \(X_i\), its two contributions integrate over \(x\geq0\) to

$$ \int_{-X_i/h}^{\infty}K(u)\,du +\int_{X_i/h}^{\infty}K(u)\,du =1. $$

To verify the equality, symmetry gives \(\int_{-X_i/h}^{\infty}K(u)\,du=1-\int_{X_i/h}^{\infty}K(u)\,du\). Thus the reflected estimator integrates to one, observation by observation.

Normalized Boundary Kernels

A second correction keeps the ordinary kernel weights but renormalizes the part that falls within the support. Define \(A(t)=\int_{-\infty}^{t}K(u)\,du\). For \(x\geq0\), use

$$ \hat f_h^{\,B}(x) =\frac{1}{nhA(x/h)} \sum_{i=1}^n K\!\left(\frac{x-X_i}{h}\right), \qquad A(x/h)>0. $$

The factor \(A(x/h)\) is the fraction of the kernel available at \(x\). At \(x=0\), it equals \(1/2\) for a symmetric kernel, so the estimator doubles the ordinary boundary estimate. For a nonnegative kernel, the estimator remains nonnegative. This normalization is designed to correct the leading bias for a density that is locally constant; it does not generally eliminate bias from a changing density.

Bias bound: Suppose \(f\) is Lipschitz near zero with constant \(L\), meaning \(|f(y)-f(z)|\leq L|y-z|\) there. If \(x/h=t\) lies in a fixed interval \([0,C]\) on which \(A(t)\) is bounded away from zero, then
$$ \left|E[\hat f_h^{\,B}(x)]-f(x)\right| \leq \frac{Lh}{A(t)}\int_{-\infty}^{t}|u|K(u)\,du =O(h). $$
Derivation: The expectation is \(A(t)^{-1}\int_{-\infty}^{t}K(u)f(x-hu)\,du\). Since \(A(t)=\int_{-\infty}^tK(u)\,du\), subtracting \(f(x)\) gives
$$ E[\hat f_h^{\,B}(x)]-f(x) =\frac{1}{A(t)}\int_{-\infty}^{t}K(u)\{f(x-hu)-f(x)\}\,du. $$
The Lipschitz condition bounds the absolute value in braces by \(Lh|u|\). Integrating this bound proves the inequality. The first absolute moment is finite because \(K\) has compact support, and the assumed lower bound on \(A(t)\) makes the bound \(O(h)\) uniformly over the stated range of \(t\). \(\square\)

Worked Example: Normalization Just Inside the Boundary

Use the same density, kernel, and bandwidth, but now evaluate at \(x=0.1\). Then \(t=x/h=0.5\). For the uniform kernel, \(A(0.5)=\int_{-1}^{0.5}(1/2)\,du=0.75\). The boundary-kernel estimator's expectation is

$$ E[\hat f_h^{\,B}(0.1)] =\frac{1}{0.75}\int_{-1}^{0.5}\frac12 e^{-(0.1-0.2u)}\,du =\frac{1-e^{-0.3}}{0.3} \approx0.8639. $$

The true density is \(f(0.1)=e^{-0.1}\approx0.9048\), so the expectation is about \(0.0409\) below the truth. The truncated kernel has been normalized, but the density is not constant over the observations receiving weight. The calculation illustrates why correcting the missing mass does not in general remove the first-order bias.

What the Corrections Do—and Do Not—Guarantee

Both methods address the leading boundary defect, but they make different adjustments. Reflection augments the contribution from each observation with its mirror image. A normalized boundary kernel divides by the available kernel mass at the evaluation point. Under the conditions above, both reproduce the boundary density to leading order in the boundary layer.

MethodBoundary adjustmentImportant limitation
Ordinary kernel estimatorNoneMissing kernel mass produces order-one relative bias within a boundary bandwidth.
ReflectionAdds a mirrored kernel contribution.It restores the leading boundary value, but generally leaves order-\(h\) bias when the density has a nonzero derivative at the boundary.
Normalized boundary kernelDivides by the available kernel mass.It reproduces a constant density locally, but generally leaves order-\(h\) bias and does not automatically integrate to one over the whole estimation domain.

The reflection limitation can be seen directly at zero. For a differentiable density, its expected value is \(2\int_0^1K(u)f(hu)\,du\). A first-order expansion of \(f(hu)\) has a term \(hu f'(0)\); unless \(f'(0)=0\), this term contributes order-\(h\) bias. Reflection has extended the density evenly across zero, but a nonzero right derivative becomes a cusp in that extension.

On a finite interval \([a,b]\), one can reflect across the left and right endpoints. The construction must account for both boundaries, especially if the bandwidth is not small relative to the interval length. The half-line formulas here should not be applied at the right endpoint without changing the reflected terms. Boundary-kernel normalizations likewise depend on which part of the kernel lies inside the domain.

Common Pitfall

Wrong reasoning: “The kernel is symmetric, so its positive and negative contributions cancel; the usual interior bias expansion applies at the boundary.” Symmetry is not enough: at the left endpoint, observations with \(X_i<0\) cannot occur, so the estimator's expectation integrates only over \(u\leq0\) when \(x=0\). Half of a symmetric kernel's mass is missing.

Correction: First write the expectation integral with its support restriction. Only then expand the density or apply a correction. Near the boundary, check the available kernel mass explicitly; do not substitute the full-kernel moment calculation used at an interior point.

Key takeaway: Boundary bias arises because the support truncates the kernel's weight. Reflection and normalized boundary kernels restore the leading contribution at the edge, but neither generally removes all boundary bias. Their remaining error depends on how the density changes near the boundary.

Check Your Understanding

Use the definitions and derivations above to answer these questions.

  1. For a symmetric unit-integral kernel and a continuous density with \(f(0)>0\), what does the ordinary estimator's expectation approach at \(x=0\) as \(h\) decreases?
  2. At \(x=ch\), what fraction of the boundary density appears in the leading limit of the ordinary estimator's expectation?
  3. Why does the reflected estimator's expectation approach \(f(0)\) at \(x=ch\) for fixed \(c\)? Identify the two kernel-mass terms.
  4. What feature of the normalized boundary kernel ensures reproduction of a locally constant density?
  5. Why can reflection still have order-\(h\) bias when the density has a nonzero derivative at the boundary?
Clinical Biostats