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

Error in id.split[[v]] : subscript out of bounds #145

Open
davidkreitmeir opened this issue Aug 9, 2024 · 2 comments
Open

Error in id.split[[v]] : subscript out of bounds #145

davidkreitmeir opened this issue Aug 9, 2024 · 2 comments

Comments

@davidkreitmeir
Copy link

Issue: I keep getting the error message Error in id.split[[v]] : subscript out of bounds but have not been able to locate in the R package scripts of lmtp the code where this issue might occur.

I attached the dataset as well as the code snippet below.

library(lmtp)
library(tidyverse)

data <- read_csv("./survival-analysis-data-lmtp-format.csv")

cols <- names(data)
W <- cols[startsWith(cols, "W")]
# Create a vector of the names of the treatment variables ordered by time
A <-  cols[startsWith(cols, "A")]
# Create a vector of the names of the censoring variables ordered by time
C <- cols[startsWith(cols, "C")]
# Create a vector of the names of the outcome variables ordered by time
Y <- cols[startsWith(cols, "Y")]
# Create a list of vectors with the covariates at each time point
# with the list ordered by time
L <- list(
  cols[str_detect(cols, "^L\\d\\.0")], cols[str_detect(cols, "^L\\d\\.1$")],
  cols[str_detect(cols, "^L\\d\\.2")], cols[str_detect(cols, "^L\\d\\.3")],
  cols[str_detect(cols, "^L\\d\\.4")], cols[str_detect(cols, "^L\\d\\.5")],
  cols[str_detect(cols, "^L\\d\\.6")], cols[str_detect(cols, "^L\\d\\.7")],
  cols[str_detect(cols, "^L\\d\\.8")], cols[str_detect(cols, "^L\\d\\.9")],
  cols[str_detect(cols, "^L\\d\\.10")], cols[str_detect(cols, "^L\\d\\.11")],
  cols[str_detect(cols, "^L\\d\\.12")], cols[str_detect(cols, "^L\\d\\.13")],
  cols[str_detect(cols, "^L\\d\\.14")], cols[str_detect(cols, "^L\\d\\.15")]
)

# check if nodes are correct 
create_node_list(trt = A, baseline = W, time_vary = L, tau = 16) 

# Create a vector indicating what algorithms should be used in the SuperLearner
sl_lib <- c("SL.glm", "SL.ranger")
set.seed(124)

# TMLE 
result.lmtp_tmle <- lmtp_tmle(
  data = data,
  trt = A,
  outcome = Y,
  baseline = W,
  time_vary = L,
  cens = C,
  shift = NULL,
  outcome_type = "survival",
  folds = 10,
  learners_trt = sl_lib,
  learners_outcome = sl_lib,
)

R session info:

R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] nnls_1.5        forcats_0.5.1   stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2    
 [6] readr_2.1.2     tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_1.3.2
[11] lmtp_1.4.0

Any help to trace down where the issue occurs would be greatly appreciated. Thanks so much in advance! And thank you for creating this awesome package!
survival-analysis-data-lmtp-format.csv

@nt-williams
Copy link
Owner

Hey! I'm on vacation without a computer, but I'll make sure to take a look into this once back in a couple of weeks.

Cheers

@nt-williams
Copy link
Owner

@davidkreitmeir I think the issue is that there isn't sufficient variation in your outcomes at each time point. For survival outcomes, outcome regressions at each time point are performed on the subset observations (at a given time-point) that are still uncensored and are still at risk of experiencing the outcome (i.e., they haven't yet experienced it). It appears this isn't the case in your data.

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

2 participants