| dScoreTest | R Documentation |
Test whether a semiparametric (e.g., GAM) or parametric (e.g., glm) regression model is well-specified. The test is a debiased (Neyman-orthogonalized) score test computed via sample splitting: on a held-out hunt sample, the null model is fit and a flexible ML algorithm is used to hunt for a direction in which the null model's score seems positive; on an independent test sample, that direction's score is evaluated to assess the significance. The test employs orthogonalization to eliminate plug-in bias from estimating the null model, so the resulting test statistic is asymptotically standard normal under the null without requiring a parametric form for the alternative.
dScoreTest(
y,
X,
score_fun,
weight_fun,
fit_method,
wls_method,
hunt.style = "optimal",
hunt.method = "grf",
hunt_fun = NULL,
debias.method = "standard",
debias_fun = NULL,
trim.outlier.hunt = TRUE,
X.cols.hunt = 1:ncol(X),
splits = c(0.5, 0.5),
arg.fit_method = NULL,
arg.wls_method = NULL,
arg.hunt_fun = NULL,
predict_fun = stats::predict,
predict_fun_hunt = NULL,
verbose = FALSE
)
y |
Numeric response vector of length n. |
X |
Numeric covariate matrix of dimension n x p. |
score_fun |
Function with signature |
weight_fun |
Function with signature |
fit_method |
Function with signature |
wls_method |
Function with signature |
hunt.style |
Hunting algorithm with the following options.
|
hunt.method |
Built-in method for hunting. Currently available:
When this is set to any other value, arguments |
hunt_fun |
Default |
debias.method |
Debiasing method. Currently available:
When set to any other value, |
debias_fun |
Default |
trim.outlier.hunt |
If |
X.cols.hunt |
Integer vector selecting which columns of
|
splits |
Numeric vector of length 2 or 3 giving the relative sizes
of the sample splits; rescaled internally to sum to one.
Default is |
arg.fit_method |
Named list of additional arguments passed to
|
arg.wls_method |
Named list of additional arguments passed to
|
arg.hunt_fun |
Extra arguments (default |
predict_fun |
Function with signature |
predict_fun_hunt |
Default |
verbose |
Default |
For most scenarios, use one of these methods instead:
Use gof_test to test whether a fitted model is
well-specified against a nonparametric alternative. S3 methods are
provided for glm (gof_test.glm), lm
(gof_test.lm) and mgcv::gam
(gof_test.gam).
Use compare_models to test a null model fit.0
against an alternative supermodel fit.1 in the same model class.
Similar to anova, method can be used to conduct a
significance test of one or more predictors.
In contrast with gof_test, this method targets the alternative
fit.1.
S3 methods are provided for glm (compare_models.glm),
lm (compare_models.lm) and mgcv::gam
(compare_models.gam).
Use hte_test_conditional to test treatment effect
heterogeneity.
Use dScoreTest directly for full control over the score,
weight, refit and hunt routines: this is the underlying engine that the
S3 methods wrap.
An object of class "dScoreTest": a list whose key elements
are the debiased test statistic t.stat and the one-sided p-value
p.val (right tail of the standard normal), along with the test-set
score residuals, the hunted direction, and the call. It has
print,
summary and
plot methods.
Maintainer: F. Richard Guo ricguo@umich.edu (ORCID) [copyright holder]
Authors:
Aditya Dhawan ad950@cam.ac.uk
Dhawan, A., Guo, F. R. and Shah, R. D. (2026). The debiased score test: hunt-and-test for semiparametric hypotheses. arXiv:2607.28861. https://arxiv.org/abs/2607.28861
Useful links:
Report bugs at https://github.com/richardkwo/dScoreTest/issues
plot.dScoreTest, summary.dScoreTest,
hunt_optimal, hunt_wls,
hunt_vanilla, new_dScoreTest
## An example for customizing a dScoreTest:
## Conditional mean independence: is E[Y | X] a function of X[, 1:3] alone,
## i.e. do X4 and X5 carry no further information once X1, X2, X3 are given?
set.seed(1)
n <- 500
X <- matrix(rnorm(n * 5), n, 5)
y <- X[, 1] + X[, 2]^2 + sin(X[, 3]) + rnorm(n) # null TRUE
y.alt <- y + X[, 4] * X[, 5] # null FALSE
## Null model class: an arbitrary function of X[, 1:3], fitted by a
## regression forest. The fitter and predict_fun subset to those columns,
## while the hunt still searches all five columns for a direction of
## misspecification. Note honesty = FALSE with tuning: an underfitted null
## model is itself misspecified, and the test then (correctly) rejects on
## that lack of fit rather than on any dependence on X4, X5.
fit_method <- function(y, X, ...)
grf::regression_forest(X[, 1:3, drop = FALSE], y,
honesty = FALSE, tune.parameters = "all")
wls_method <- function(y, X, w, ...)
grf::regression_forest(X[, 1:3, drop = FALSE], y, sample.weights = w,
honesty = FALSE, tune.parameters = "all")
predict_fun <- function(fit, X, ...)
predict(fit, X[, 1:3, drop = FALSE])$predictions
## Square loss l(f, y) = (y - f)^2 / 2 gives the score l'(f, y) = f - y
## (a negative residual) and the weight l''(f, y) = 1.
score_fun <- function(fit, y, X, ...) predict_fun(fit, X) - y
weight_fun <- function(fit, X, ...) rep(1, nrow(X))
## Null holds: no evidence against it.
dScoreTest(y, X, score_fun, weight_fun, fit_method, wls_method,
predict_fun = predict_fun)
## Null fails: the dependence on X4 and X5 is detected.
dScoreTest(y.alt, X, score_fun, weight_fun, fit_method, wls_method,
predict_fun = predict_fun)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.