Closed bernard-liew closed 2 years ago
Thank you!
The data that you load had a categorical A and multivariate blip - so you have to set the SL library that supports it. The error message is complaining about the lack of multinomial function.
Book section 8.7.2 has an example SL library you could use:
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()
Q_learner <- Lrnr_sl$new( learners = list(lrn_xgboost_100, lrn_mean, lrn_glm), metalearner = Lrnr_nnls$new() )
mn_metalearner <- make_learner(Lrnr_solnp, loss_function = loss_loglik_multinomial, learner_function = metalearner_linear_multinomial ) g_learner <- make_learner(Lrnr_sl, list(lrn_xgboost_100, lrn_xgboost_500, lrn_mean), mn_metalearner)
learners <- list(lrn_xgboost_50, lrn_xgboost_100, lrn_xgboost_500, lrn_mean, lrn_glm) b_learner <- create_mv_learners(learners = learners)
Hi,
Thank you for this very useful package. I am very new to tmle. When I tried running the below code (from your online book) to try the VIM function, it keeps throwing up an error. This also happens with my data. At first, I thought it was due to the presence of missing data, but there isn't any.
Thank you for taking the time to assist.
Regards, Bernard
`library(data.table) library(sl3) library(tmle3) library(tmle3mopttx) library(devtools)
data("data_cat_realistic")
data <- data_cat_realistic
Define sl3 library and metalearners:
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() lrn_lasso <- Lrnr_glmnet$new()
Define the Q learner:
Q_learner <- Lrnr_sl$new( learners = list(lrn_lasso, lrn_mean, lrn_glm), metalearner = Lrnr_nnls$new() )
Define the g learner:
g_learner <- Lrnr_sl$new( learners = list(lrn_lasso, lrn_glm), metalearner = Lrnr_nnls$new() )
Define the B learner:
b_learner <- Lrnr_sl$new( learners = list(lrn_lasso,lrn_mean, lrn_glm), metalearner = Lrnr_nnls$new() )
specify outcome and treatment regressions and create learner list
learner_list <- list(Y = Q_learner, A = g_learner, B = b_learner) data$W1<-ifelse(data$W1<quantile(data$W1)[2],1,ifelse(data$W1<quantile(data$W1)[3],2,3))
node_list <- list( W = c("W3", "W4", "W2"), A = c("W1", "A"), Y = "Y" )
initialize a tmle specification
tmle_spec_vim <- tmle3_mopttx_vim( V=c("W2"), type = "blip2", learners = learner_list, maximize = FALSE, method = "SL", complex = TRUE, realistic = FALSE )
vim_results <- tmle3_vim(tmle_spec_vim, data, node_list, learner_list, adjust_for_other_A = TRUE ) `
Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found In addition: Warning message: In private$.train(subsetted_task, trained_sublearners) : Lrnr_glm_fast_TRUE_Cholesky failed with message: Error in outcome_type$glm_family(return_object = TRUE): Family object requested for family that does not have a generator. You're probably using an unsupported learner/outcome_type combination. Specify family manually. . It will be removed from the stack Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Failed on Lrnr_nnls_FALSE Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found In addition: There were 11 warnings (use warnings() to see them) Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found In addition: Warning message: In private$.train(subsetted_task, trained_sublearners) : Lrnr_glm_fast_TRUE_Cholesky failed with message: Error in outcome_type$glm_family(return_object = TRUE): Family object requested for family that does not have a generator. You're probably using an unsupported learner/outcome_type combination. Specify family manually. . It will be removed from the stack Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Error in get(family, mode = "function", envir = parent.frame()) : object 'multinomial' of mode 'function' was not found Failed on Lrnr_nnls_FALSE Error in { : task 1 failed - "NA/NaN/Inf in foreign function call (arg 1)" In addition: There were 11 warnings (use warnings() to see them)