Nothing
test_that("singleEventSurvival supports cox model with and without covariates", {
df <- data.frame(
subject_id = 1:16,
time = c(4, 6, 9, 11, 13, 16, 18, 21, 7, 8, 10, 14, 17, 19, 24, 28),
status = c(1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0),
age_years = c(23, 31, 44, 56, 62, 36, 41, 70, 29, 33, 48, 53, 65, 39, 58, 72),
score = c(1.2, 0.8, 1.5, 1.0, 1.1, 0.9, 1.6, 1.3, 0.7, 1.4, 1.2, 1.1, 1.5, 0.95, 1.05, 1.25)
)
out_base <- OdysseusSurvivalModule:::singleEventSurvival(
survivalData = df,
model = "cox",
covariates = NULL,
confType = "none"
)
expect_true("overall" %in% names(out_base))
out_cov <- OdysseusSurvivalModule:::singleEventSurvival(
survivalData = df,
model = "cox",
covariates = c("age_years", "score")
)
expect_true("overall" %in% names(out_cov))
expect_true(all(c("data", "summary") %in% names(out_cov$overall)))
})
test_that("singleEventSurvival validates ageBreaks content", {
df <- data.frame(
subject_id = 1:8,
time = c(3, 5, 8, 10, 14, 17, 19, 23),
status = c(1, 0, 1, 0, 1, 0, 1, 0),
age_years = c(19, 24, 37, 46, 52, 61, 69, 74)
)
expect_error(
OdysseusSurvivalModule:::singleEventSurvival(
survivalData = df,
model = "km",
strata = c("age_group"),
ageBreaks = list(c(10, 20, 30))
),
"length 2"
)
expect_error(
OdysseusSurvivalModule:::singleEventSurvival(
survivalData = df,
model = "km",
strata = c("age_group"),
ageBreaks = list(c(Inf, 20))
),
"min age"
)
})
test_that("internal age helpers and logrank helper handle edge cases", {
expect_error(
OdysseusSurvivalModule:::.validate_age_groups(list(c(10, 20), c(20, 30))),
"non-overlapping"
)
valid <- OdysseusSurvivalModule:::.validate_age_groups(list(c(0, 17), c(18, 44), c(45, Inf)))
expect_equal(valid$lowers, c(0, 18, 45))
labels <- OdysseusSurvivalModule:::.make_age_labels(valid$lowers, valid$uppers)
expect_equal(labels, c("0-17", "18-44", "45+"))
no_event_df <- data.frame(
time_scaled = c(1, 2, 3, 4),
status = c(0, 0, 0, 0),
gender = c("Male", "Female", "Male", "Female")
)
expect_null(OdysseusSurvivalModule:::.logrank_from_df(no_event_df, "gender"))
one_group_df <- data.frame(
time_scaled = c(1, 2, 3, 4),
status = c(1, 1, 0, 1),
gender = c("Male", "Male", "Male", "Male")
)
expect_null(OdysseusSurvivalModule:::.logrank_from_df(one_group_df, "gender"))
})
test_that("singleEventSurvival parametric variants return overall entry", {
df <- data.frame(
subject_id = 1:14,
time = c(3, 5, 7, 9, 11, 13, 16, 18, 21, 24, 27, 30, 34, 38),
status = c(1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
age_years = c(21, 34, 29, 47, 53, 41, 38, 66, 58, 62, 49, 71, 55, 68)
)
for (dist in c("exponential", "lognormal", "loglogistic")) {
out <- OdysseusSurvivalModule:::singleEventSurvival(
survivalData = df,
model = dist,
covariates = c("age_years"),
probs = c(0.8, 0.5, 0.2)
)
expect_true("overall" %in% names(out))
expect_true(is.list(out$overall$summary))
}
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.