Skip to content

Commit 2cd31bc

Browse files
authored
Add tests for survival models (#506)
* Add tests for survival * desc * bayestestR
1 parent 9814742 commit 2cd31bc

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: modelbased
33
Title: Estimation of Model-Based Predictions, Contrasts and Means
4-
Version: 0.11.1.1
4+
Version: 0.11.1.2
55
Authors@R:
66
c(person(given = "Dominique",
77
family = "Makowski",
@@ -39,7 +39,7 @@ BugReports: https://github.com/easystats/modelbased/issues
3939
Depends:
4040
R (>= 3.6)
4141
Imports:
42-
bayestestR (>= 0.15.3),
42+
bayestestR (>= 0.16.0),
4343
datawizard (>= 1.0.2),
4444
insight (>= 1.3.0),
4545
parameters (>= 0.25.0),
@@ -91,6 +91,7 @@ Suggests:
9191
RWiener,
9292
sandwich,
9393
see (>= 0.11.0),
94+
survival,
9495
testthat (>= 3.2.1),
9596
vdiffr,
9697
withr

R/format.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,8 @@ format.marginaleffects_contrasts <- function(x, model = NULL, p_adjust = NULL, c
661661
estimate_name <- tools::toTitleCase(predict_type)
662662
} else if (!predict_type %in% c("none", "link") && (info$is_binomial || info$is_bernoulli)) {
663663
estimate_name <- "Probability"
664+
} else if (predict_type == "survival" && info$is_survival) {
665+
estimate_name <- "Probability"
664666
} else if (predict_type %in% c("zprob", "zero")) {
665667
estimate_name <- "Probability"
666668
} else if (predict_type %in% c("response", "invlink(link)") && (info$is_beta || info$is_orderedbeta)) {

tests/testthat/test-estimate_means.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,40 @@ test_that("estimate_means, error on invalid type", {
464464
regex = "The option provided"
465465
)
466466
})
467+
468+
469+
test_that("estimate_means, coxph-survival", {
470+
skip_if_not_installed("survival")
471+
model <- survival::coxph(
472+
survival::Surv(dtime, death) ~ hormon + age + I(age^2),
473+
data = survival::rotterdam
474+
)
475+
emm <- estimate_means(
476+
model,
477+
c("dtime=c(1000, 2000, 3000, 4000)", "hormon"),
478+
predict = "survival"
479+
)
480+
expect_named(
481+
emm,
482+
c("dtime", "hormon", "Probability", "SE", "CI_low", "CI_high", "z")
483+
)
484+
expect_equal(
485+
emm$Probability,
486+
c(0.8982, 0.86121, 0.7775, 0.70451, 0.68016, 0.58485, 0.58174, 0.47051),
487+
tolerance = 1e-4
488+
)
489+
emm <- estimate_means(
490+
model,
491+
"hormon",
492+
predict = "risk"
493+
)
494+
expect_named(
495+
emm,
496+
c("hormon", "Mean", "SE", "CI_low", "CI_high", "z")
497+
)
498+
expect_equal(
499+
emm$Mean,
500+
c(0.82661, 1.15039),
501+
tolerance = 1e-4
502+
)
503+
})

0 commit comments

Comments
 (0)