nhejazi/txshift

error handling matrix W

nhejazi opened this issue · 1 comments

For some reason, the following simple example (with a matrix W, instead of a vector) does not work:

library(data.table)
library(tidyverse)
library(condensier)
library(txshift)
set.seed(429153)

# simulate simple data for tmle-shift sketch
n_obs <- 1000  # number of observations
n_w <- 3  # number of baseline covariates
tx_mult <- 2  # multiplier for the effect of W = 1 on the treatment

## baseline covariates -- simple, binary
W <- replicate(n_w, rbinom(n_obs, 1, 0.5))

## create treatment based on baseline W
A <- as.numeric(rnorm(n_obs, mean = tx_mult * (rowSums(W) > 2), sd = 1))

# create outcome as a linear function of A, W + white noise
Y <- A + (1 / exp(rowSums(W))) + rnorm(n_obs, mean = 0, sd = 1)

# create data for examination
obs <- as.data.table(list(W, A, Y))
setnames(obs, c(paste0("W", seq_len(ncol(W))), "A", "Y"))

tmle_glm_shift_1 <- tmle_txshift(W = W, A = A, Y = Y, delta = 0.5,
                                 fluc_method = "standard",
                                 ipcw_fit_args = NULL,
                                 g_fit_args = list(fit_type = "glm", nbins = 20,
                                                   bin_method = "dhist",
                                                   bin_estimator = speedglmR6$new(),
                                                   parfit = FALSE),
                                 Q_fit_args = list(fit_type = "glm",
                                                   glm_formula = "Y ~ .")
                                )
tmle_glm_shift_1

...it returns an error:

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL'

closed by #9