View source: R/add-functions.R
| add_hazard | R Documentation |
Add (cumulative) hazard based on the provided data set and model.
If ci=TRUE confidence intervals (CI) are also added. Their width can
be controlled via the se_mult argument. The method by which the
CI are calculated can be specified by ci_type.
This is a wrapper around
predict.gam. When reference is specified, the
(log-)hazard ratio is calculated. In addition to models fit with
gam/bam or glm,
shape-constrained additive models fit with scam are
supported (e.g., for monotone baseline hazards). For scam models all
calculations (including delta-method and simulation based confidence
intervals) are based on the re-parametrized coefficients and their
covariance matrix, i.e., on the same normal approximation that underlies
the standard errors reported by scam itself.
add_hazard(newdata, object, ...)
## Default S3 method:
add_hazard(
newdata,
object,
reference = NULL,
type = c("response", "link"),
ci = TRUE,
se_mult = 2,
ci_type = c("default", "delta", "sim"),
overwrite = FALSE,
time_var = NULL,
nsim = 100L,
alpha = 0.05,
...
)
add_cumu_hazard(newdata, object, ...)
## Default S3 method:
add_cumu_hazard(
newdata,
object,
ci = TRUE,
se_mult = 2,
overwrite = FALSE,
time_var = NULL,
interval_length = "intlen",
boundary = TRUE,
check_grouping = TRUE,
...
)
## S3 method for class 'pamm_ic'
add_hazard(
newdata,
object,
ci = TRUE,
alpha = 0.05,
nsim = 500L,
time_var = NULL,
...
)
## S3 method for class 'pamm_ic'
add_cumu_hazard(
newdata,
object,
ci = TRUE,
alpha = 0.05,
nsim = 500L,
time_var = NULL,
interval_length = "intlen",
check_grouping = TRUE,
...
)
newdata |
A data frame or list containing the values of the model covariates at which predictions
are required. If this is not provided then predictions corresponding to the
original data are returned. If |
object |
a fitted |
... |
Further arguments passed to |
reference |
A data frame with number of rows equal to |
type |
Either |
ci |
|
se_mult |
Factor by which standard errors are multiplied for calculating the confidence intervals. |
ci_type |
The method by which standard errors/confidence intervals
will be calculated. Default transforms the linear predictor at
respective intervals. |
overwrite |
Should hazard columns be overwritten if already present in
the data set? Defaults to |
time_var |
Name of the variable used for the baseline hazard. Defaults
to |
nsim |
Total number of pooled posterior draws used for the interval. |
alpha |
Significance level for pooled confidence intervals (a
|
interval_length |
The variable in newdata containing the interval lengths.
Can be either bare unquoted variable name or character. Defaults to |
boundary |
Logical. If |
check_grouping |
Logical. If |
When computing cumulative hazards or survival probabilities across groups,
the input data must be grouped via group_by() prior to calling
add_cumu_hazard() or add_surv_prob(), so that the cumulative
quantity is accumulated within each covariate profile rather than across the
whole dataset. If newdata still contains several profiles per group
(i.e.\ repeated time_var values within a group, typically a forgotten
group_by()), the functions now stop with an error rather than
returning silently incorrect results. Set check_grouping = FALSE to
skip this safeguard. Note the check detects the common mis-grouping
cases – in particular any grid built with make_newdata, where
profiles share time values – but cannot catch hand-built grids that stack
profiles with disjoint time grids, as these are indistinguishable from a
single profile with time-varying covariates.
See the workflow vignette
for a worked example.
predict.gam,
add_surv_prob
ped <- tumor[1:50,] %>% as_ped(Surv(days, status)~ age)
pam <- mgcv::gam(ped_status ~ s(tend)+age, data = ped, family=poisson(), offset=offset)
ped_info(ped) %>% add_hazard(pam, type="link")
ped_info(ped) %>% add_hazard(pam, type = "response")
ped_info(ped) %>% add_cumu_hazard(pam)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.