# Generated by roxytest: Do not edit by hand!
# File R/apply_hr.r: @tests
test_that("Function apply_hr() @ L62", {
dist1 <- define_surv_param("exp", rate = 0.25)
expect_equal(
apply_hr(dist1, 0.5),
create_list_object(c('surv_ph', 'surv_dist'), dist = dist1, hr = 0.5)
)
expect_equal(
apply_hr(dist1, 0.5),
apply_hr(apply_hr(dist1, 0.5), 1)
)
expect_equal(
apply_hr(dist1, 0.25),
apply_hr(apply_hr(dist1, 0.5), 0.5)
)
expect_equal(
apply_hr(dist1, 0.5),
apply_hr(dist1, log(0.5), TRUE)
)
expect_error(
apply_hr('foo', 0.5),
'Error applying hazard ratio, invalid survival distribution provided.',
fixed = TRUE
)
expect_error(
apply_hr(dist1, 'foo'),
'Error applying hazard ratio, "hr" must be numeric.',
fixed = TRUE
)
expect_error(
apply_hr(dist1, NA_real_),
'Error applying hazard ratio, "hr" cannot be NA.',
fixed = TRUE
)
expect_error(
apply_hr(dist1, -2),
'Error applying hazard ratio, "hr" cannot be negative.',
fixed = TRUE
)
})
test_that("Function surv_prob.surv_ph() @ L135", {
dist1 <- define_surv_param("exp", rate = 0.50)
dist2 <- define_surv_param("exp", rate = 0.25)
dist3 <- apply_hr(dist1, 0.5)
dist4 <- apply_hr(dist1, log(0.5), TRUE)
expect_equal(
surv_prob(dist2, seq_len(100)),
surv_prob(dist3, seq_len(100))
)
expect_equal(
surv_prob(dist2, seq_len(100)),
surv_prob(dist4, seq_len(100))
)
})
test_that("Function print.surv_ph() @ L151", {
dist1 <- apply_hr(define_surv_param('exp', rate = 0.025), 0.5)
expect_output(
print(dist1),
'A proportional hazards survival distribution:
* Hazard Ratio: 0.5
* Baseline Distribution: An exponential distribution (rate = 0.025).',
fixed = T
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.