Currently, handling missing data is not supported. As far as I know, kernel models do not take easily account for missing data, so incorporating this into the estimation might be tricky. It is of course possible to perform multiple imputation before density ratio estimation, and estimate the density ratio weights on the imputed data. Perhaps this is sufficient. This works quite easily as follows:
library(mice)
#>
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following objects are masked from 'package:base':
#>
#> cbind, rbind
library(densityratio)
meth <- make.method(boys)
meth["bmi"] <- "~I(wgt/(hgt/100)^2)"
pred <- make.predictorMatrix(boys)
pred[c("hgt", "wgt"), "bmi"] <- 0
imp <- mice::mice(boys, m = 5, maxit = 10, method = meth, predictorMatrix = pred, print = FALSE)
impdats <- complete(imp, "all")
W <- lapply(
impdats, \(x) {
nu <- subset(x, reg %in% c("north", "east"), select = -reg)
de <- subset(x, reg %in% c("south", "west"), select = -reg)
weights <- ulsif(nu, de, progressbar = FALSE) |> predict(subset(x, select = -reg))
weights
}
)
# incorrect SE estimation because this treats the weights as known, but okay.
Map(function(x, w) {
lm(tv ~ age + hgt + wgt, data = x, weights = pmax(0, w))
}, x = impdats, w = W
) |> pool()
#> Class: mipo m = 5
#> term m estimate ubar b t dfcom
#> 1 (Intercept) 5 10.5980794 1.4309811034 0.8012719184 2.3925074054 744
#> 2 age 5 1.2426221 0.0119588944 0.0159546998 0.0311045341 744
#> 3 hgt 5 -0.1726749 0.0002541340 0.0001741265 0.0004630858 744
#> 4 wgt 5 0.2327654 0.0003673657 0.0006995607 0.0012068385 744
#> df riv lambda fmi
#> 1 23.456406 0.6719350 0.4018906 0.4471053
#> 2 10.180888 1.6009540 0.6155257 0.6738638
#> 3 18.742459 0.8222111 0.4512162 0.5016966
#> 4 7.975054 2.2851149 0.6955966 0.7510685
Created on 2025-05-06 with reprex v2.1.1
Currently, handling missing data is not supported. As far as I know, kernel models do not take easily account for missing data, so incorporating this into the estimation might be tricky. It is of course possible to perform multiple imputation before density ratio estimation, and estimate the density ratio weights on the imputed data. Perhaps this is sufficient. This works quite easily as follows:
Created on 2025-05-06 with reprex v2.1.1