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

non-numeric argument to binary operator #14

Open
yangliu6768 opened this issue Nov 30, 2023 · 1 comment
Open

non-numeric argument to binary operator #14

yangliu6768 opened this issue Nov 30, 2023 · 1 comment

Comments

@yangliu6768
Copy link

Hi,

When I tried to learn the individualized best treatment effect, I found an error called non-numeric argument to binary operator.

Here is my code:

library(data.table)
library(sl3)
library(tmle3)
library(tmle3mopttx)
library(devtools)
set.seed(111)

data <- read.csv("updated_dat_r.csv",header = TRUE)
node_list <- list(
W = colnames(data)[1:148],
A = 'tm_grp',
Y = "death.no_readmission"
)
processed <- process_missing(data, node_list)
data <- processed$data
node_list <- processed$node_list

Initialize few of the learners:

lrn_xgboost_50 <- Lrnr_xgboost$new(nrounds = 50)
lrn_xgboost_100 <- Lrnr_xgboost$new(nrounds = 100)
lrn_xgboost_500 <- Lrnr_xgboost$new(nrounds = 500)
lrn_mean <- Lrnr_mean$new()
lrn_glm <- Lrnr_glm_fast$new()

Define the Q learner, which is just a regular learner:

Q_learner <- Lrnr_sl$new(
learners = list(lrn_glm #,
# lrn_xgboost_100, lrn_mean,
),
metalearner = Lrnr_nnls$new()
)

Q_learner <- Lrnr_hal9001$new()

Define the g learner, which is a multinomial learner:

specify the appropriate loss of the multinomial learner:

mn_metalearner <- make_learner(Lrnr_solnp,
eval_function = loss_loglik_multinomial,
learner_function = metalearner_linear_multinomial
)
g_learner <- make_learner(Lrnr_sl, list(# lrn_glm
lrn_xgboost_50

lrn_xgboost_100, lrn_xgboost_500, lrn_mean

),
mn_metalearner)

g_learner <- Lrnr_hal9001$new()

Define the Blip learner, which is a multivariate learner:

learners <- list(
lrn_xgboost_50,

lrn_xgboost_100, lrn_xgboost_500,

lrn_mean,

lrn_glm)
b_learner <- create_mv_learners(learners = learners)

specify outcome and treatment regressions and create learner list

learner_list <- list(Y = Q_learner, A = g_learner, B = b_learner)

initialize a tmle specification

tmle_spec <- tmle3_mopttx_blip_revere(
type = "blip3",
learners = learner_list,
maximize = FALSE, complex = TRUE,
realistic = FALSE, resource = 1
)

complex = TRUE must use all V to determine treatment rule

realistic = TRUE: respect the possitivity issue

resource: 0.5, can only give half of them treatment

fit the TML estimator

fit <- tmle3(tmle_spec, data, node_list, learner_list)
fit

And here is the error:

Error in .Primitive("*")(dots[[1L]][[1L]], dots[[2L]][[1L]]) :
non-numeric argument to binary operator

And the traceback:

8.stop(first_error$value)
7.self$compute_step()
6.scheduler$compute()
5.delayed_fit$compute(job_type = sl3_delayed_job_type(), progress = verbose)
4.likelihood_def$train(tmle_task)
3.point_tx_likelihood(tmle_task, learner_list)
2.tmle_spec$make_initial_likelihood(tmle_task, learner_list)
1.tmle3(tmle_spec, data, node_list, learner_list)

Could you please help me? Thank you very much! I appreciate your help.

@yangliu6768
Copy link
Author

Here is the data.
updated_dat_r.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant