RdistNN provides distributional nearest-neighbor (DNN) methods for conditional average treatment effects (CATE) and nonparametric regression in R and Stata. The packages combine local estimation with jackknife standard errors, tuning tools, and diagnostics.
Software Packages
RdistNN for R
RdistNN estimates treatment-effect heterogeneity and conditional outcome means at selected covariate profiles. Its main workflows are cate_dnn() for CATE and np_dnn() for nonparametric regression, with shared DNN weighting, tuning, and diagnostic tools.
- Multi-target CATE and regression estimates with tuning-grid inspection
- CATE from AIPW, Robinson, or precomputed scores, with overlap and weight diagnostics
- Confidence intervals, prediction, and ggplot2 postestimation views
- Fast and leave-one-out jackknife inference, DNN weights and paper-replication tools
Start here: Open the R quick start below, install the package, run a CATE or regression example, then inspect diagnostics.
R quick start
Before installing, configure a working C++17 toolchain for source builds; on Windows, use Rtools for your R version. Install pak if needed. It installs required package dependencies, including Rcpp.
# install.packages("pak")
pak::pak("JakobJuergens/RdistNN")
library(RdistNN)
demo_cate <- cate_demo_data(n = 300, p = 2, design = "hetero", seed = 1)
df <- demo_cate$data
df$m1_oracle <- df$m0_oracle + df$tau_oracle
fit_cate <- cate_dnn(
data = df,
x_cols = c("X1", "X2"), y_col = "Y", t_col = "D",
m0_col = "m0_oracle", m1_col = "m1_oracle", e_col = "e_oracle",
x0 = c(0, 0), method = "exact", k = 1L,
tuning = tuning_dnn_paper(),
se = TRUE, jackknife = "fast"
)
summary(fit_cate)
confint(fit_cate)
diagnostics(fit_cate)
demo <- np_demo_data(n = 250, p = 2, design = "sinusoidal", seed = 1)
fit <- np_dnn(
data = demo$data,
x_cols = c("X1", "X2"), y_col = "Y",
x0 = c(0, 0), method = "exact", k = 1L,
tuning = tuning_dnn_paper(),
se = TRUE, jackknife = "fast"
)
fit$mu
fit$se
diagnostics(fit)
RdistNN for Stata
RdistNN_stata provides the companion CATE and regression workflows through native estimation, stored results, diagnostics, and graphs. It uses supplied nuisance predictions or scores for CATE; nuisance-model fitting remains separate from the package.
cate_dnnfor CATE andnp_dnnfor nonparametric regression- Multi-target estimates, covariance matrices, and integrated tuning grids
- Dedicated NP and CATE diagnostics plus Stata-native plotting and dashboards
- Deterministic R/Stata parity fixtures for estimates, inference, tuning, and diagnostics
Start here: Open the Stata quick start below, install the package, run a CATE or regression example, then inspect diagnostics.
Stata quick start
net install rdistnn, from("https://raw.githubusercontent.com/JakobJuergens/RdistNN_stata/master/") replace
clear
set obs 300
set seed 1
gen x1 = rnormal()
gen x2 = rnormal()
gen e = invlogit(0.5*x1 - 0.5*x2)
gen D = (runiform() < e)
gen m0 = 1 + x1 - x2
gen m1 = m0 + 0.5 + 0.5*sin(x1)
gen Y = m0 + D*(m1 - m0) + rnormal()*0.5
cate_dnn Y, tcol(D) xcols(x1 x2) x0(0 0) ///
ecol(e) m0col(m0) m1col(m1)
cate_dnn_diagnostics
cate_dnn_plot, type(dashboard)
sysuse auto, clear
np_dnn price, xcols(weight length) x0(3000 190)
np_dnn_diagnostics
np_dnn_plot, type(dashboard)
Designed as companion implementations
Both packages share DNN rank weights, the paper-default k = 1 kernel, a finite-sample tuning default of lambda = 0.4, and target-level diagnostics. The R package adds simulation and extension tools; the Stata package provides native estimation and postestimation commands.
Pointwise inference
CATE examples use oracle nuisance inputs to illustrate the interface. With estimated nuisances, orthogonality alone does not justify full-sample reuse: valid inference also requires the accompanying paper’s rate and deletion-stability conditions and control of localization bias. Diagnostics describe local information and overlap; they do not verify these theoretical conditions.
Experimental: PLQR
The plqr_dnn interfaces for partially linear quantile regression (PLQR) evaluate localized orthogonal score moments at supplied coefficient values. They do not solve for local coefficients and remain experimental. In R, coefficient-level uncertainty calculations additionally require supplied threshold-density values; Stata currently reports score-moment covariance rather than coefficient inference.