diff --git a/DESCRIPTION b/DESCRIPTION index 0a6f58249..f723d97a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: modelbased Title: Estimation of Model-Based Predictions, Contrasts and Means -Version: 0.11.1.1 +Version: 0.11.1.2 Authors@R: c(person(given = "Dominique", family = "Makowski", @@ -39,7 +39,7 @@ BugReports: https://github.com/easystats/modelbased/issues Depends: R (>= 3.6) Imports: - bayestestR (>= 0.15.3), + bayestestR (>= 0.16.0), datawizard (>= 1.0.2), insight (>= 1.3.0), parameters (>= 0.25.0), @@ -91,6 +91,7 @@ Suggests: RWiener, sandwich, see (>= 0.11.0), + survival, testthat (>= 3.2.1), vdiffr, withr diff --git a/R/format.R b/R/format.R index 9a2722e89..175bc8042 100644 --- a/R/format.R +++ b/R/format.R @@ -661,6 +661,8 @@ format.marginaleffects_contrasts <- function(x, model = NULL, p_adjust = NULL, c estimate_name <- tools::toTitleCase(predict_type) } else if (!predict_type %in% c("none", "link") && (info$is_binomial || info$is_bernoulli)) { estimate_name <- "Probability" + } else if (predict_type == "survival" && info$is_survival) { + estimate_name <- "Probability" } else if (predict_type %in% c("zprob", "zero")) { estimate_name <- "Probability" } else if (predict_type %in% c("response", "invlink(link)") && (info$is_beta || info$is_orderedbeta)) { diff --git a/tests/testthat/test-estimate_means.R b/tests/testthat/test-estimate_means.R index d358b5da8..292d6a9e0 100644 --- a/tests/testthat/test-estimate_means.R +++ b/tests/testthat/test-estimate_means.R @@ -464,3 +464,40 @@ test_that("estimate_means, error on invalid type", { regex = "The option provided" ) }) + + +test_that("estimate_means, coxph-survival", { + skip_if_not_installed("survival") + model <- survival::coxph( + survival::Surv(dtime, death) ~ hormon + age + I(age^2), + data = survival::rotterdam + ) + emm <- estimate_means( + model, + c("dtime=c(1000, 2000, 3000, 4000)", "hormon"), + predict = "survival" + ) + expect_named( + emm, + c("dtime", "hormon", "Probability", "SE", "CI_low", "CI_high", "z") + ) + expect_equal( + emm$Probability, + c(0.8982, 0.86121, 0.7775, 0.70451, 0.68016, 0.58485, 0.58174, 0.47051), + tolerance = 1e-4 + ) + emm <- estimate_means( + model, + "hormon", + predict = "risk" + ) + expect_named( + emm, + c("hormon", "Mean", "SE", "CI_low", "CI_high", "z") + ) + expect_equal( + emm$Mean, + c(0.82661, 1.15039), + tolerance = 1e-4 + ) +})