vartype = "simu" is accepted for the kernel estimator but crashes - #29
vartype = "simu" is accepted for the kernel estimator but crashes#29soodoku wants to merge 2 commits into
Conversation
interflex() validates vartype against c("simu","delta","bootstrap") for every
estimator, but kernel.R implements only the bootstrap and delta branches. With
estimator = "kernel" and vartype = "simu" neither runs, and output assembly
fails with "object 'diff.output.all.list' not found", which tells the caller
nothing.
The default is unaffected: the signature sets vartype = "delta". The two ways in
are passing "simu" explicitly, or passing NULL, which line 271 turns into
"simu".
Rejects the combination during validation, alongside the existing
estimator/option constraints. Full suite unchanged at FAIL 1 | SKIP 4 | PASS 344
(the one failure is a missing optional 'ranger' dependency, pre-existing).
|
Correcting my own closing observation above, having dug further — I was partly wrong and would rather say so than leave it standing. I wrote that a user is "asked for a clustering variable that is then unused". That is only true under the default (cluster-assigned treatment, 40 clusters, bandwidth fixed so nothing else varies) The block bootstrap lands at ~0.66–0.74, against ~0.71 for the linear estimator's clustered SEs on the same data. So clustered inference for the kernel estimator is available and correct — via I also traced why So please disregard that paragraph — there is no correctness problem there, and I am not proposing any change for it. The only thing that might still be worth a look is that None of this affects the |
My first version rejected the combination unconditionally, which broke a call pattern that works today. The whole vartype dispatch in kernel.R sits inside `if (CI)` (bootstrap 2034, delta 2410, closing 2560), and the `if (!CI)` branch at 2562 builds its output without consulting vartype at all. So estimator = "kernel", vartype = "simu", CI = FALSE returns a valid interflex object on master, and the unconditional stop() turned that into an error. Now only the failing combination is rejected: vartype=simu CI=TRUE : rejected with a clear message vartype=delta CI=TRUE : ok vartype=bootstrap CI=TRUE : ok vartype=simu CI=FALSE : ok vartype=delta CI=FALSE : ok vartype=bootstrap CI=FALSE : ok CI is validated at interflex.R:256, before this check at :281.
interflex()acceptsvartype = "simu"for every estimator (R/interflex.R:273), butR/kernel.Ronly implements the"bootstrap"(line 2034) and"delta"(line 2410) branches. Withestimator = "kernel"andvartype = "simu", neither branch runs, the output objects are never built, and assembly fails with an internal error that gives the caller nothing to act on.Reproduction
On
master:Unconditional — independent of
nsimu,diff.values, bandwidth and sample size.Worth noting the default is safe: the signature sets
vartype = "delta"(line 20), so ordinary calls are unaffected. Two ways in: passingvartype = "simu"explicitly, or passingvartype = NULL, which line 271 turns into"simu".Change
Reject the combination during validation, where the other estimator/option constraints already live (e.g. the
pcse-requires-linear check a few lines below):I have deliberately not tried to implement a simulation branch for the kernel estimator — that is a feature decision, and if you would rather have it than an error, this patch is the wrong change.
Verification
kernel+simunow stops with an actionable message;kernel+delta/bootstrapandlinear+simuare unaffected.cd tests && NOT_CRAN=true Rscript testthat.R: FAIL 1 | SKIP 4 | PASS 344 both before and after. The single failure istest-dml.R:19("ml_method = "randomforest"requires the 'ranger' package"), which is a missing optional dependency in my environment, pre-existing onmasterand unrelated.Separate observation, not addressed here
vcov.typenever reaches the kernel estimator — the string does not occur inR/kernel.R, andinterflex()forwards it only to the linear (line 1064) and binning (line 1128) estimators. With the bandwidth held fixed so nothing else varies, kernel standard errors are bit-identical undervcov.type = "robust"andvcov.type = "cluster":On the same cluster-assigned data the linear estimator's clustered SEs are about 4.5x its robust ones, so the choice is not immaterial there.
I am raising this rather than patching it because
?interflexdoes scopevcov.typeto "linear models", so ignoring it for the kernel estimator may well be intended. The part that seems worth a second look either way is thatinterflex()still requiresclwhenvcov.type == "cluster"(line 301) even for the kernel estimator, so a user is asked for a clustering variable that is then unused, with no warning. Happy to send a small warning patch if that would be useful.