Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions inst/tinytest/test_outcome_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test_outcome_continuous()

test_outcome_phreg <- function() {
phreg <- mets::phreg
phreg.par <- mets::phreg.par
phreg_weibull <- mets::phreg_weibull
Surv <- survival::Surv #nolint

par1 <- list(scale = 1 / 100, shape = 2)
Expand Down Expand Up @@ -183,13 +183,20 @@ test_outcome_phreg <- function() {
xx0 <- covar(1e4)
dd <- outcome(xx0) |> cbind(xx0)

cox1 <- phreg.par(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(coef(cox1), c(log(unlist(par1)), 0, 0),
tolerance = 0.2)
cox1 <- phreg_weibull(Surv(time, status) ~ a + x, data = dd)
# par1$scale ** par1$shape because of transformation in coxWeibull.lvm
expect_equivalent(
coef(cox1),
c(log(par1$scale ** par1$shape), 0, 0, log(par1$shape)),
tolerance = 0.2
)

cox0 <- phreg.par(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(coef(cox0), c(log(unlist(par0)), 0, 0),
tolerance = 0.2)
cox0 <- phreg_weibull(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(
coef(cox0),
c(log(par1$scale ** par1$shape), 0, 0, log(par1$shape)),
tolerance = 0.2
)

## Specify parameters
outcome <- setargs(outcome_phreg,
Expand All @@ -200,14 +207,19 @@ test_outcome_phreg <- function() {
)
dd <- outcome(xx0) |> cbind(xx0)

cox1 <- phreg.par(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(coef(cox1), c(log(unlist(par1)), coef(fit1)),
tolerance = 0.2)

cox0 <- phreg.par(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(coef(cox0), c(log(unlist(par0)), coef(fit1)),
tolerance = 0.2)
cox1 <- phreg_weibull(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(
coef(cox1),
c(log(par1$scale ** par1$shape), coef(fit1), log(par1$shape)),
tolerance = 0.2
)

cox0 <- phreg_weibull(Surv(time, status) ~ a + x, data = dd)
expect_equivalent(
coef(cox0),
c(log(par0$scale ** par1$shape), coef(fit1), log(par0$shape)),
tolerance = 0.2
)

# Specify design via `lp` argument
outcome <- setallargs(
Expand Down
Loading