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

fitSmoothHazard.fit and formula_time = ~1 #148

Open
turgeonmaxime opened this issue Jul 8, 2021 · 0 comments
Open

fitSmoothHazard.fit and formula_time = ~1 #148

turgeonmaxime opened this issue Jul 8, 2021 · 0 comments

Comments

@turgeonmaxime
Copy link
Collaborator

There's a bug when we try to specify formula_time = ~1 in fitSmoothHazard.fit. This would happen, for example, if we assumed an exponential hazard.

library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
N <- 1000; p <- 30
nzc <- 0.33 * p
x <- matrix(rnorm(N * p), N, p)
dimnames(x)[[2]] <- paste0("x", seq_len(p))
beta <- rnorm(nzc)
fx <- x[, seq(nzc)] %*% (0.33 * beta)
hx <- exp(fx)
ty <- rexp(N, hx)
tcens <- rbinom(n = N,
                prob = 0.3,
                size = 1) # censoring indicator
y <- cbind(time = ty, status = 1 - tcens)

# This one works
out1 <- fitSmoothHazard.fit(x, y, time = "time", 
                            event = "status",
                            ratio = 10, 
                            formula_time = ~ time)

# This one doesn't
out2 <- fitSmoothHazard.fit(x, y, time = "time", 
                            event = "status",
                            ratio = 10, 
                            formula_time = ~ 1)
#> Error in fitSmoothHazard.fit(x, y, time = "time", event = "status", ratio = 10, : length(timeVar) == 1 is not TRUE

Created on 2021-07-08 by the reprex package (v2.0.0)

It should be fairly easy to fix. The culprit are these lines here:

casebase/R/fitting.R

Lines 274 to 276 in c4d208c

timeVar <- if (length(formula_time) == 3) {
all.vars(formula_time[[3]])
} else all.vars(formula_time)

When formula_time = ~1, we end up with timeVar = character(0), hence the error.

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

No branches or pull requests

1 participant