Nothing
# One-hour reference resolution is a safety contract, not merely display text.
reference_sim <- function(unit = "hours", multiplier = 1) {
d <- simulate_tls(family = "binomial", CTmax = 36, z = 4, seed = 318)
d$duration <- d$duration * multiplier
standardize_data(
d, temp = "temp", duration = "duration",
n_total = "total", n_surv = "survived", duration_unit = unit
)
}
test_that("standardized duration and omitted reference time are always minutes", {
hours <- reference_sim("hours", 1)
minutes <- reference_sim("minutes", 60)
seconds <- reference_sim("seconds", 3600)
days <- reference_sim("days", 1 / 24)
fits <- lapply(list(hours, minutes, seconds, days), function(d) {
suppressWarnings(fit_4pl(d, family = "binomial", quiet = TRUE))
})
expect_identical(vapply(fits, function(f) f$meta$t_ref, numeric(1)),
rep(60, 4))
expect_equal(lapply(list(hours, minutes, seconds, days), `[[`, "duration"),
rep(list(hours$duration), 4))
expect_equal(vapply(fits, function(f) as.numeric(logLik(f)), numeric(1)),
rep(as.numeric(logLik(fits[[1]])), 4), tolerance = 1e-8)
expect_equal(vapply(fits, function(f) get_ctmax(f)$estimate, numeric(1)),
rep(get_ctmax(fits[[1]])$estimate, 4), tolerance = 1e-8)
})
test_that("fit_tls resolves standardized column and formula interfaces", {
minutes <- reference_sim("minutes", 60)
col <- suppressWarnings(fit_tls(
minutes, y = n_surv, n = n_total, time = duration, temp = temp,
family = "binomial", quiet = TRUE
))
frm <- suppressWarnings(fit_tls(
tls_bf(n_surv | trials(n_total) ~ time(duration) + temp(temp)),
data = minutes, family = "binomial", quiet = TRUE
))
expect_identical(col$tref, 60)
expect_identical(frm$tref, 60)
expect_equal(as.numeric(logLik(col)), as.numeric(logLik(frm)), tolerance = 1e-8)
})
test_that("bare minute data default to the one-hour reference with a warning", {
d <- simulate_tls(family = "binomial", CTmax = 36, z = 4, tref = 60, seed = 319)
expect_warning(
fallback <- fit_tls(d, y = survived, n = total, time = duration, temp = temp,
family = "binomial", quiet = TRUE),
"defaults to 60 minutes"
)
expect_identical(fallback$tref, 60)
expect_no_warning(
explicit <- fit_tls(d, y = survived, n = total, time = duration, temp = temp,
family = "binomial", tref = 60, quiet = TRUE)
)
expect_identical(explicit$tref, 60)
})
test_that("unknown input duration units are rejected before fitting", {
expect_error(
reference_sim("weeks", 1),
"Cannot convert.*weeks"
)
})
test_that("an explicit reference is never converted to the one-hour convention", {
minutes <- reference_sim("minutes", 60)
one_minute <- suppressWarnings(
fit_4pl(minutes, family = "binomial", t_ref = 1, quiet = TRUE)
)
one_hour <- suppressWarnings(
fit_4pl(minutes, family = "binomial", quiet = TRUE)
)
expect_identical(one_minute$meta$t_ref, 1)
expect_identical(one_hour$meta$t_ref, 60)
expect_false(isTRUE(all.equal(get_ctmax(one_minute)$estimate,
get_ctmax(one_hour)$estimate)))
})
test_that("an explicit minute reference is invariant to the input duration unit", {
hours <- reference_sim("hours", 1)
one_hour <- suppressWarnings(fit_4pl(hours, family = "binomial", quiet = TRUE))
one_minute <- suppressWarnings(
fit_4pl(hours, family = "binomial", t_ref = 1, quiet = TRUE)
)
expect_identical(one_hour$meta$t_ref, 60)
expect_identical(one_minute$meta$t_ref, 1)
expect_false(isTRUE(all.equal(get_ctmax(one_hour)$estimate,
get_ctmax(one_minute)$estimate)))
})
test_that("reference time must be finite when supplied explicitly", {
expect_error(
freqTLS:::tls_resolve_tref(Inf),
"finite positive"
)
})
test_that("column-interface errors identify an unresolved required column", {
d <- simulate_tls(family = "binomial", seed = 320)
expect_error(
fit_tls(d, y = nope, n = total, time = duration, temp = temp,
family = "binomial", tref = 1, quiet = TRUE),
"y.*nope"
)
expect_error(
fit_tls(d, n = total, time = duration, temp = temp,
family = "binomial", tref = 1, quiet = TRUE),
"y.*column"
)
})
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.