Estimate a localized nonparametric mean by combining observed outcomes with DNN-based local weights.
Usage
np_dnn(
data = NULL,
x_cols = NULL,
y_col = NULL,
y = NULL,
X = NULL,
Y = NULL,
X0 = NULL,
x0 = NULL,
distance = "l2",
method = c("exact", "asymp"),
k = 1L,
s = NULL,
tuning = NULL,
tuning_mode = c("default", "grid"),
normalize = TRUE,
se = TRUE,
jackknife = c("fast", "loo", "none"),
ctx = NULL,
return = c("W")
)Arguments
- data
Optional data frame containing covariates and outcome columns. Column names must be non-missing, non-empty, and unique.
- x_cols
Names or indices of covariate columns in
data.- y_col
Name or index of the outcome column in
data.- y
Optional numeric outcome vector of length
n. In the data-frame interface, use this instead ofy_col.- X
Numeric matrix (
n x p) for the matrix interface.- Y
Numeric outcome vector of length
nfor the matrix interface.- X0
Numeric matrix (
m x p) of target points; mutually exclusive withx0.- x0
Numeric vector of length
pfor a single target point.- distance
Distance name or specification (for example
"l2").- method
One of
"exact"or"asymp"for DNN weights.- k
Integer DNN neighbour count inside each size-
ssubsample. The paper theory usesk = 1(the default).- s
Integer kernel order (undersmoothing parameter), or
NULL. When bothsandtuningareNULL(the default),sis resolved from the paper undersmoothing ruletuning_dnn_paper(), \(s = \lfloor 0.4 n^{(k_x+1)/(k_x+2)} \rfloor\). Note that small fixed values such ass = 1(ork = s) yield uniform weights and hence no localization; a warning is emitted in that case.- tuning
Optional kernel-order tuning specification. When supplied,
smust be omitted and is resolved fromtuning.- tuning_mode
One of
"default"or"grid"."default"evaluates the defaultsonly."grid"evaluates the feasible candidates fromtuning, or fromtuning_dnn_paper()whentuningis omitted, and stores candidate-level estimates, standard errors, diagnostics, and metadata intuning_grid. Grid mode cannot be combined with explicits.- normalize
Logical; renormalize columns of
Wto sum to 1.- se
Logical; compute delete-1 jackknife standard errors.
- jackknife
One of
"fast","loo", or"none"."fast"(default) uses cached full-sample ranks with delete-1 rank updates,"loo"recomputes leave-one-out weights directly, and"none"skips SEs.- ctx
Optional context passed to distance and ranking components.
- return
Optional extras in addition to the always-returned
mu,se, andmeta. Allowed values:c("W", "ranks", "ord", "dx", "y", "ess", "neighbors", "tuning"). Theneighborsextra returns the firstknearest observations used inside each size-ssubsample, not the full DNN weight support.
Value
An object of class np_result with components:
mu: estimated local mean values at target points;se: optional jackknife standard errors;x0: them x pmatrix of evaluation points, with covariate column names propagated from the training data when available;meta: metadata (n,m,p,k,s,method,distance);tuning_grid: in grid mode, a list withcandidates,estimates,diagnostics, andmetatables. Candidate diagnostics report top-5 weight concentration separately from the estimator'sk;optional extras requested via
return.
Details
Two interfaces are supported.
Data-frame interface (recommended): pass
data,x_cols, and eithery_colory(exactly one).Matrix interface: pass
X, one ofX0orx0, andY.
For method = "exact", DNN weights are computed from the full rank
permutation at each target. The exact support extends through rank
n - s + k (n - s + 1 in the paper-faithful k = 1 case); this is not
an s-nearest-neighbor truncation. The "fast" jackknife option reuses
the full-sample rank matrix and updates ranks under deletion.
tuning_mode = "default" evaluates only the default kernel order and
preserves the ordinary scalar-fit return shape. tuning_mode = "grid"
evaluates the feasible candidates in tuning, or the paper default tuning
grid when tuning is omitted, and attaches a tidy tuning_grid payload.
The primary mu, se, meta, and optional extras such as W, ranks,
ess, and neighbors remain anchored to the default candidate. Full
per-candidate weight matrices are not stored. Candidate diagnostics include
ess, max_weight, top_n, top5_weight_share, and degenerate;
top_n is fixed at 5 and is independent of the estimator's k.