Fast rate of a nearest neighbor estimate for a global parameter

Author: Yen-Chi Chen (University of Washington)
Date: 07/08/2026

Quick summary

Local versus global parameter

We consider a simple nonparametric regression model where our data consists of IID random variables
(X1,Y1),,(Xn,Yn)(X_1,Y_1),\cdots, (X_n,Y_n)
from some unknown distributions such that XiRdX_i\in\mathbb{R}^d.
We further assume the following data generating process:
Yi=m(Xi)+ϵi,Y_i = m(X_i) + \epsilon_i,
where XiϵiX_i\perp \epsilon_i and ϵ1,,ϵn\epsilon_1,\cdots, \epsilon_n are IID mean 00 noises with variance Var(ϵi)=σ2<{\sf Var}(\epsilon_i) = \sigma^2<\infty.

It is well-knonwn that we cannot estimate the local parameter m(x)m(x) at a very fast rate unless it is super smooth. Roughly speaking, if m(x)m(x) has bounded ss-times derivatives, the fastest rate that we can achieve is
m^(x)m(x)=OP(ns/(2s+d)).\hat m(x) - m(x) = O_P\left(n^{-s/(2s+d)}\right).
The kNN estimator achieves this rate with a good choice of kns/(2s+d)k \sim n^{-s/(2s+d)}.
Note that conventional choice is s=2s=2 since we often assume that the function m(x)m(x) is twice differentiable.

Now we consider estimating a global parameter
θ=E(m2(X)).\theta = \mathbb{E}(m^2(X)).
This parameter is often of interest due to its relation to the variance σ2=E((Ym(X))2)\sigma^2 = \mathbb{E}((Y-m(X))^2).

How to estimate θ\theta in a nonparametric setting?

1-NN estimator

It turns out that a simple and accurate estimator is the 1-NN estimator
θ^n=1ni=1nYiYN(i),\hat \theta_n = \frac{1}{n} \sum_{i=1}^n Y_i Y_{N(i)},
where
N(i)=argminjiXjXiN(i) = {\sf argmin}_{j\neq i} \|X_j-X_i\|
is the index of the ii-th observation.

Convergence rate

Here is an interesting fact about θ^n\hat \theta_n: It is very accurate in the sense that its convergence rate is (ignoring some logn\log n factors)
θ^nθ=OP(1n+n1/d)\hat \theta_n - \theta = O_P\left(\frac{1}{\sqrt{n}} + n^{-1/d}\right)
when mm is Lipschitz continuous.
Namely, we actually achieve a parametric rate when d2d\leq 2!

The above rate has two components:

Convergenace rate

Here is how we obtain the above rate. First, observed that
Yi=m(Xi)+ϵi,YN(i)=m(XN(i))+ϵN(i)Y_i = m(X_i) + \epsilon_i,\qquad Y_{N(i)} = m(X_{N(i)}) + \epsilon_{N(i)}
so as long as mm is Lipschitz continuous, we have
m(XN(i))=m(Xi)+δi,δi=OP(XiXN(i))=OP(n1/d).m(X_{N(i)}) = m(X_i) + \delta_i,\qquad \delta_i = O_P(\|X_i - X_{N(i)}\|) = O_P(n^{-1/d}).
Putting this back into the estimator θ^n\hat \theta_n, we obtain
θ^n=1ni=1nYiYN(i)=1ni=1n(m(Xi)+ϵi)(m(Xi)+δi+ϵN(i))=1ni=1nm2(Xi)signal+m(Xi)δibias+ϵN(i)Yi+ϵiYN(i)noise.\begin{align*} \hat \theta_n &= \frac{1}{n}\sum_{i=1}^nY_i Y_{N(i)} \\ &= \frac{1}{n}\sum_{i=1}^n(m(X_i) +\epsilon_i) (m(X_i) + \delta_i + \epsilon_{N(i)}) \\ &= \frac{1}{n}\sum_{i=1}^n \underbrace{m^2(X_i)}_\text{signal} + \underbrace{m(X_i) \delta_i}_\text{bias} + \underbrace{\epsilon_{N(i)} Y_i + \epsilon_i Y_{N(i)}}_\text{noise}. \end{align*}

Clearly, the signal component 1ni=1nm2(Xi)\frac{1}{n}\sum_{i=1}^n m^2(X_i) results in a n\sqrt{n}-consistent estimator of θ\theta. So we just need to control the remaining quantities.

Bias component

Since it is well-known that δi=OP(n1/d)\delta_i = O_P(n^{-1/d}), we immediately have
1ni=1nm(Xi)δi=OP(n1/d)\frac{1}{n}\sum_{i=1}^n m(X_i) \delta_i =O_P(n^{-1/d})
under very mild conditions of m(x)m(x) and the underly density function of the covariate pXp_X.

Noise component (part of the variance)

The remaining quantity
Vˉn=1ni=1nϵN(i)Yi+ϵiYN(i)=Vi\bar V_n = \frac{1}{n}\sum_{i=1}^n \underbrace{\epsilon_{N(i)} Y_i +\epsilon_i Y_{N(i)}}_{=V_i}
behaves like average of noises and under proper moment conditions of ϵi\epsilon_i, we have
Var(Vi)=σV2<.{\sf Var} (V_i) = \sigma^2_V<\infty.

However, this is NOT enough to argue that Var(Vˉn)=OP(n1/2){\sf Var}(\bar V_n) = O_P(n^{-1/2}) because V1,,VnV_1,\cdots, V_n are dependent due to the 1NN component.
Formally, we have
Var(Vˉn)=1n2i=1nVar(Vi)+1n2ij=1nCov(Vi,Vj).{\sf Var}(\bar V_n) = \frac{1}{n^2}\sum_{i=1}^n{\sf Var}(V_i) + \frac{1}{n^2}\sum_{i\neq j=1}^n {\sf Cov}(V_i, V_j).
The first variance is controlled as we have mentioned. The tricky part is the second component the covariance.

Kissing number

Fortunately, here is a useful geometry quantity called kissing number in dd-dimensional (Euclidean) space.

Simply put, for any sets of points in Rd\mathbb{R}^d and we create a 1-NN graph, i.e., we add an edge between Xi,XjX_i,X_j if one is an 1-NN to the other, the maximal degree of any point is bounded by a constant KdK_d known as the kissing number. This constant is purely geometry property that only depends on the dimension dd and not the sample size (number of points).
To see how this occurs, consider a given point X0X_0 and try to place points around it such that X0X_0 is the 1NN of all the points you want to place near X0X_0. If you have place X1X_1, then X2X_2 cannot be in the ball B(X1,X1X0)B(X_1, \|X_1-X_0\|) otherwise X2X_2's 1NN will be X1X_1, not X0X_0 (or X1X_1's 1NN will be X2X_2, not X0X_0). Therefore, if you have placed X1,,XkX_1,\cdots, X_k, the next point Xk+1X_{k+1} will be confined to a much smaller region to ensure X0X_0 is the 1NN point. Evetually, the entire space will be filled up and there is no way you can place any more points whose 1-NN is X0X_0.

Using the idea of kissing number and the fact that Vi,VjV_i,V_j will be correlated only if {Xi,XN(i)}{Xj,XN(j)}\{X_i, X_{N(i)}\} \cap \{X_j, X_{N(j)}\}\neq \emptyset, we realize that the set {j:Cov(Vi,Vj)0}\{j: {\sf Cov}(V_i,V_j)\neq 0\} has at most Cd2KdC_d \leq 2K_d elements. So most pairs Cov(Vi,Vj)=0{\sf Cov}(V_i,V_j) = 0, and we conclude that
1n2ij=1nCov(Vi,Vj)2nKd×σV2n2=O(n1),\frac{1}{n^2}\sum_{i\neq j=1}^n {\sf Cov}(V_i, V_j) \leq \frac{ 2 n K_d \times \sigma^2_V}{n^2} = O(n^{-1}),
where σV2<\sigma^2_V<\infty is just some constant. Therefore, we conclude that
Var(Vˉn)=O(n1){\sf Var}(\bar V_n) = O(n^{-1})
and hence
θ^nθ=OP(1n+n1/d).\hat \theta_n - \theta = O_P\left(\frac{1}{\sqrt{n}} + n^{-1/d}\right).

Estimating higher-order moments

The same estimator can be applied to cases where we are interested in the average of an LL-th local moment. Specifically, consider θL=E(mL(X))\theta_L = \mathbb{E}(m^L(X)).
We can use a (L1)(L-1)-NN estimator:
θ^L=1ni=1nYi=1L1YNL1(i),\hat \theta_L = \frac{1}{n}\sum_{i=1}^n Y_i \prod_{\ell=1}^{L-1} Y_{N_{L-1}(i)},
where NL1(i)N_{L-1}(i) is the indices of the (L1)(L-1)-NN of XiX_i.

Using the same derivation, the convergence rate of θ^L\hat \theta_L remains the same:
θ^LθL=OP(1n+n1/d).\hat \theta_L - \theta_L = O_P\left(\frac{1}{\sqrt{n}} + n^{-1/d}\right).

Polynomial transformation

If we are interestinf θf=E(f(m(X)))\theta_f = \mathbb{E}(f(m(X))) such that ff is a polynomial function, then the above kNN trick applies with kk to be the highest order of the polynomial minus 1.
For a concreate example, suppose we are interested in estimating μ=E((m2(X)5)2)=E(m4(X)10m2(X)+25)\mu = \mathbb{E}((m^2(X) - 5)^2) = \mathbb{E}(m^4(X) - 10 m^2(X) + 25), we can apply a 3NN estimator of E(m4(X))\mathbb{E}(m^4(X)) and a 1NN estimator of E(m2(X))\mathbb{E}(m^2(X)) to obtain the estimate of μ\mu.

Another example of a slightly faster rate: η=E(em(X))\eta = \mathbb{E}(e^{m(X)})

Now we consider the problem of estimating η=E(em(X))\eta = \mathbb{E}(e^{m(X)}). Since the exponential is a inifinite-order polynomial, the above fixed kk approach is not applicable so we have to consider k=knk=k_n\rightarrow \infty as nn\rightarrow\infty.

Consider a simple plug-in estimator:
η^k=1ni=1nem^k(Xi).\hat \eta_k = \frac{1}{n}\sum_{i=1}^n e^{\hat m_k(X_i)}.

Rate improvement for global parameter

When m(x)m(x) is twice differentiable,
η^kη=OP(ns/(s+d)),\hat \eta_k - \eta = O_P\left(n^{-s/(s+d)}\right),
which is (slightly) faster than the rate of estimating the local parameter
m^k(x)m(x)=OP(ns/(2s+d)).\hat m_k(x) - m(x) = O_P\left(n^{-s/(2s+d)}\right).

How does the rate improvement occur?

To see how the rate improve occurs, consider the orcale estimator
η~=1ni=1nem(Xi).\tilde \eta = \frac{1}{n}\sum_{i=1}^n e^{m(X_i)}.
Clearly, η~η=OP(1n)\tilde \eta - \eta = O_P\left(\frac{1}{\sqrt{n}}\right).
But this estimator and the kNN estimator are similar via a Taylor expansion:
em^k(Xi)em(Xi)em(Xi)(m^k(Xi)m(Xi))+12em(Xi)(m^k(Xi)m(Xi))2.e^{\hat m_k(X_i)} - e^{m(X_i)} \approx e^{m(X_i)}(\hat m_k(X_i) - m(X_i)) + \frac{1}{2} e^{m(X_i)}(\hat m_k(X_i) - m(X_i))^2.

Therefore,
η^η~1ni=1nem(Xi)(m^k(Xi)m(Xi))(linear)+1ni=1n12em(Xi)(m^k(Xi)m(Xi))2(MSE).\begin{align*} \hat \eta - \tilde \eta \approx \underbrace{\frac{1}{n}\sum_{i=1}^n e^{m(X_i)}(\hat m_k(X_i) - m(X_i))}_\text{(linear)} + \underbrace{\frac{1}{n}\sum_{i=1}^n\frac{1}{2} e^{m(X_i)}(\hat m_k(X_i) - m(X_i))^2}_\text{(MSE)}. \end{align*}

Therefore, the dominating error is the bias from (linear) and the variance from (MSE), which corresponds to the rate
η^kη=η^kη~+η~η=OP(1n+1k+(kn)s/d)\hat \eta_k - \eta = \hat \eta_k - \tilde \eta + \tilde \eta - \eta = O_P\left(\frac{1}{\sqrt{n}}+\frac{1}{k}+\left(\frac{k}{n}\right)^{s/d}\right)
and under the optimal choice of kns/(s+d)k\sim n^{s/(s+d)}, we obtain the rate
η^kη=OP(ns/(s+d)).\hat \eta_k - \eta = O_P\left(n^{-s/(s+d)}\right).

von Mises exapnsion

The above derivation is known as the von Mises expansion. In short, the von Mises expansion uses the fact that when estimating a global parameter, we have a summation/integration process over each XiX_i, which offers a way to reduce the stochastic errors of a local estimator due to the averaging process.

Generalization to other smooth transformation

The von Mises expansion can be generalized to other case of E(f(m(X)))\mathbb{E}(f(m(X))) for smooth ff. As long as the function ff is smooth in the sense that we can apply a Taylor expansion, we are able to improve the convergence rate via the same von Mises expansion.

An example of no improvements: ρ=E(I(m(X)>0.5))\rho = \mathbb{E}(I(m(X)>0.5))

When the parameter of interest is not a polynomial functional, this kNN trick fails and we have to retreat to the conventional local estimator, although we may still have a fast rate with some other conditions.

Consider the quantity
ρ=E(I(m(X)>0.5)).\rho = \mathbb{E}(I(m(X) > 0.5)).
This is a common quantity in binary classification, where it measures the predictive probability of class 11 if we convert the regression model into a classifier.

No rate improvement

Unfortunately, the above kNN tricks cannot be applied to ρ\rho because the transformation I(m(x)>0.5)I(m(x) > 0.5) is non-smooth (it is actually discontinuous). So the convergence rate for an estimator ρ^k=1ni=1nI(m^k(Xi)>0.5)\hat \rho_k = \frac{1}{n}\sum_{i=1}^n I(\hat m_k(X_i)> 0.5) will be
ρ^kρ=OP(ns/(2s+d))\hat \rho_k - \rho = O_P\left(n^{-s/(2s+d)}\right)
when the function mm is ss-times differentiable.

To see this, if you pick any fixed kk, say k=5k=5, the kNN estimator m^k\hat m_k has a non-vanishing variance. So for any xx with m(x)0.5m(x) \approx 0.5, this non-vanishing variance could push it up or down the critical threshold 0.50.5, leading to a non-vanishing error regardless of the sample size. Therefore, we have to set kk to slowly increase with respect to the sample size to achieve consistency. Moreover, the Taylor expansion method in the previous section is not applicable since the indicator function is not differentiable.

Improving rate by Tsybakov's margin condition

Note that in this scenario, we may improve the convergence rate via the Tsybakov's margin condition:

Tsybakov's margin condition

We assume that P(m(X)0.50.5)<A0ϵαP(|m(X) - 0.5|\leq 0.5) < A_0 \cdot\epsilon^\alpha for some constants A0A_0 and α\alpha.

Under Tsybakov's margin condition, the convergence rate of an kk-NN estimator of ρ\rho is
ρ^kρ=OP(nsα2s+d)\hat \rho_k - \rho = O_P\left(n^{-\frac{s \alpha}{2s+d}}\right)
when we choose kns/(2s+d)k \sim n^{s/(2s+d)}.

Rate comparison for estimating a global parameter

Now we see three regimes of the convergence rate. To put everything in the same condition, we consider mm to be only Lipschitz smooth. A sufficient condition is mm to have a uniformly bounded derivative. So we can view this as the case of s=1s=1.
Recall that the convergence rate for estimating a local parameter m(x)m(x) is
m^k(x)m(x)=OP(n1/(2+d))\hat m_k(x) - m(x) = O_P\left(n^{-1/(2+d)}\right)
when we choose kn1/(2+d)k\sim n^{1/(2+d)}.

In this case, we can see three convergence rates: