| predict.profile_tls | R Documentation |
predict() evaluates the fitted four-parameter thermal-load-sensitivity
model at new temperature-by-duration cells, using exactly the
same forward map as the TMB engine in src/profile_tls.cpp:
## S3 method for class 'profile_tls'
predict(
object,
newdata,
type = c("survival", "link", "midpoint", "parameters"),
re.form = c("population", "conditional"),
...
)
## S3 method for class 'freq_tls'
predict(
object,
newdata,
type = c("survival", "link", "midpoint", "parameters"),
re.form = c("population", "conditional"),
...
)
object |
A |
newdata |
A data frame with numeric columns |
type |
One of |
re.form |
How to handle fitted random intercepts. |
... |
Reserved; must be empty. |
Here CTmax is the critical thermal maximum at the reference duration
tref; z is thermal sensitivity in degrees per order-of-magnitude change
in duration;
low and up are the fitted lower and upper survival asymptotes; and k
controls the curve's steepness. The model fits log_z = log(z) internally,
then reports positive natural-scale z values.
All supported curves use mid = log10(tref) - (temp - CTmax) / z. The
selected curve then maps eta = k * (log10(duration) - mid) to survival.
The default log-logistic fraction is plogis(-eta); curve also accepts
the log-normal and two midpoint-centred Weibull forms.
Four response types are available:
"survival" (default) returns the fitted survival probability in (0, 1).
"link" returns the logit of the survival probability,
qlogis(survival).
"midpoint" returns the temperature-dependent curve midpoint mid on the
log10(duration) axis (constant within a temperature, so the duration
column is ignored for this type but a temp column is still required).
"parameters" returns the row-specific natural-scale CTmax, z, low,
up, and k values. This is useful for interacted formula designs; the
duration column may be omitted.
newdata must also contain every predictor used by the fitted fixed-effect
designs for CTmax, log_z, low, up, or log_k. For a grouped column-
interface fit, supply group with values from the fitted group_levels.
For a formula fit, a literal tls_bf() call preserves the fixed-design
formulas needed to rebuild transformed or interacted terms. If the model was
instead passed through a formula-object variable, predict() can rebuild
direct numeric design columns but asks the user to refit with a literal
tls_bf() call when a transformed or interacted design cannot be recovered
safely.
For type = "parameters", a data frame with one row per row of
newdata and columns CTmax, z, low, up, and k. Otherwise a
numeric vector with one element per row; survival values lie in (0, 1).
d <- simulate_tls(family = "binomial", times = c(30, 60, 120, 240, 480),
CTmax = 36, z = 4, tref = 60, seed = 1)
fit <- fit_tls(d, y = survived, n = total, time = duration, temp = temp,
family = "binomial", tref = 60)
nd <- expand.grid(temp = c(34, 36, 38), duration = c(60, 120, 240))
predict(fit, nd, type = "survival")
# A continuous predictor used by CTmax and log_z must also be in newdata.
d$x <- rep(c(-1, 1), length.out = nrow(d))
fit_x <- fit_tls(
tls_bf(survived | trials(total) ~ time(duration) + temp(temp),
CTmax ~ x, log_z ~ x),
data = d, family = "binomial", tref = 60
)
predict(fit_x, data.frame(temp = 36, duration = 60, x = c(-1, 1)))
# Choose population or fitted-group prediction explicitly for an RE fit.
dre <- simulate_tls(family = "binomial", CTmax = 36, z = 4,
times = c(30, 60, 120, 240, 480), tref = 60,
re_sd = 1, n_re_groups = 8, seed = 2)
fit_re <- fit_tls(
tls_bf(survived | trials(total) ~ time(duration) + temp(temp),
CTmax ~ 1 + (1 | colony)),
data = dre, family = "binomial", tref = 60
)
colony <- as.character(ranef(fit_re)$group[1])
nd_re <- data.frame(temp = 36, duration = 60, colony = colony)
predict(fit_re, nd_re, re.form = "population")
predict(fit_re, nd_re, re.form = "conditional")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.