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

absoluteRisk and glmnet #147

Open
turgeonmaxime opened this issue Jun 30, 2021 · 0 comments
Open

absoluteRisk and glmnet #147

turgeonmaxime opened this issue Jun 30, 2021 · 0 comments
Assignees
Labels

Comments

@turgeonmaxime
Copy link
Collaborator

We still have a bug when using absoluteRisk with family = "glmnet". Specifically, the issue arises when we use fitSmoothHazard.fit with a matrix of covariate X without any column names:

library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
library(survival)
library(mvtnorm)

n <- 75
p <- 5

# Generate covariates
X <- rmvnorm(n = n, sigma = diag(p))
# Generate failure times
fail_times <- rexp(n = n,
                   rate = 1)
# Generate censoring times
cens_times <- runif(n = n, min = 1, max = 3) *
    rexp(n = n, rate = 1)

times <- pmin(fail_times, cens_times)
status <- as.numeric(fail_times < cens_times)

model <- fitSmoothHazard.fit(X, Surv(times, event = status), 
                             time = "time", event = "status", 
                             family = "glmnet")

# Next line fails
absoluteRisk(model, time = 1,
             newdata = X[1:5, ])
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 88

# No longer fails if we add column names
colnames(X) <- paste0("V", seq_len(p))
absoluteRisk(model, time = 1,
             newdata = X[1:5, ])
#>  time                                                  
#>     0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#>     1 0.5258076 0.5258076 0.5258076 0.5258076 0.5258076

Created on 2021-06-30 by the reprex package (v2.0.0)

The culprit is these lines:

casebase/R/absoluteRisk.R

Lines 253 to 255 in c4d208c

newdata2 <- current_obs[,
colnames(newdata) != object$timeVar,
drop = FALSE]

When X has no column names, colnames(newdata) is simply NULL and therefore colnames(newdata) != object$timeVar is a zero-length logical vector. As a consequence, newdata2 is a matrix without any column!

@turgeonmaxime turgeonmaxime self-assigned this Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant