Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict returns invalid density estimates when trim=TRUE (the default) #32

Open
jeremyrcoyle opened this issue Sep 24, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@jeremyrcoyle
Copy link

jeremyrcoyle commented Sep 24, 2021

The density estimates from predict can integrate to more than 1 when trimming is enabled. Perhaps some renormalization is needed after trimming?

# example from the docs
set.seed(1234)
n_train <- 50
w <- runif(n_train, -4, 4)
a <- rnorm(n_train, w, 0.5)
# HAL-based density estimator of A|W
haldensify_fit <- haldensify(
  A = a, W = w, n_bins = 10L, lambda_seq = exp(seq(-1, -10, length = 100)),
  # the following arguments are passed to hal9001::fit_hal()
  max_degree = 5, smoothness_orders = 0, num_knots = NULL,
  reduce_basis = 1 / sqrt(length(a))
)
# predictions to recover conditional density of A|W
new_a <- seq(-4, 4, by = 0.1)
new_w <- rep(0, length(new_a))

# the density integrates to much more than 1
pred_dens <- predict(haldensify_fit, new_A = new_a, new_W = new_w)
pracma::trapz(new_a, pred_dens)
# 1.4869

# the density integrates to ~ 1 with trim = FALSE
pred_dens2 <- predict(haldensify_fit, new_A = new_a, new_W = new_w, trim = FALSE)
pracma::trapz(new_a, pred_dens2)
# 0.9955347
@nhejazi nhejazi added the bug Something isn't working label Sep 24, 2021
@nhejazi nhejazi self-assigned this Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants