ncn-foreigners/nonprobsvy

MI, DR and multiple variables

BERENZ opened this issue · 2 comments

BERENZ commented

Issue

If I provide more than one y in MI or DR than the summary is different and the resulting object outcome contains only one model (I don't know which one).

Generate data

library(data.table)
library(nonprobsvy)
set.seed(2023-10-19)
n_reps <- 50
N <- 50000
n <- 1000
x1 <- rnorm(N,1,1)
x2 <- rexp(N,1)
alp <- rnorm(N)
epsilon <- rnorm(N)
y11 <- 1 + x1 + x2 + alp + epsilon
y12 <- 0.5*(x1-1.5)^2 + x2^2 + alp + epsilon
y21 <- rbinom(N,1,plogis(1 + x1 + x2 + alp))
y22 <- rbinom(N,1,plogis(0.5*(x1-1.5)^2 + x2^2 + alp))
p1 <- plogis(x2)
p2 <- plogis(-3+(x1-1.5)^2+(x2-2)^2)
pop_data <- data.frame(x1,x2,y11,y12,y21,y22,p1,p2) |> setDT()

sample_prob <- pop_data[sample(1:N, n),]
sample_prob$w <- N/n
sample_prob_svy <- svydesign(ids=~1, weights = ~w, data = sample_prob)
sample_bd1 <- pop_data[rbinom(N,1,pop_data$p1)==1, ]
sample_bd1$w_naive <- N/nrow(sample_bd1)
sample_bd2 <- pop_data[rbinom(N,1,pop_data$p2)==1, ]
sample_bd2$w_naive <- N/nrow(sample_bd2)

MI

m1 <- nonprob(outcome = y11 + y12  ~ x1 + x2, data=sample_bd2, svydesign=sample_prob_svy)
m1$outcome

DR

In case of DR is the same. Only one set of selection and outcome coefficients is reported.

m2 <- nonprob(selection = ~ x1 + x2, outcome = y11 + y12  ~ x1 + x2, data=sample_bd2, svydesign=sample_prob_svy)

potential improvements TODO:

  • adjust the summary so that it returns info for one target, in case of more, appropriate information.
  • in the case of a larger number of targets, one selection list (for propensity score estimation)is returned and an outcome list containing as many lists as there are targets.