Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from RaphaelS1/parametric
Browse files Browse the repository at this point in the history
fixbug
  • Loading branch information
RaphaelS1 authored Mar 9, 2024
2 parents 0344750 + 92f4337 commit f418791
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/parametric.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ parametric <- function(
call <- match.call()

data <- clean_train_data(formula, data, time_variable, status_variable, x, y, reverse)
olddata <- data.frame(data$x, data$y)
# HACKY MESS
form <- as.formula(sprintf(
"survival::Surv(%s) ~ %s",
paste0(colnames(data$y), collapse = ","),
paste0(colnames(data$x), collapse = "+")
))
fit <- survival::survreg(form, olddata, x = TRUE, ...)

fit <- survival::survreg(survival::Surv(data$y) ~ data$x, x = TRUE, ...)

location <- as.numeric(fit$coefficients[1])

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test_parametric.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,12 @@ test_that("discrete = continuous when expected", {
expect_equal(s_cont, t(p_disc$surv))
}
})

test_that("fix formula bug", {
lung2 = survival::lung
lung2$status = lung2$status - 1
lung2 = lung2[-14, c("time", "status", "ph.ecog")]

fit = parametric(data = lung2, time_variable = "time", status_variable = "status")
expect_silent(predict(fit, newdata = lung2, form = "aft"))
})

0 comments on commit f418791

Please sign in to comment.