View source: R/survival_ln_mixture-predict.R
predict.survival_ln_mixture | R Documentation |
Predict from a Lognormal Mixture Model
## S3 method for class 'survival_ln_mixture'
predict(
object,
new_data,
type,
eval_time,
interval = "none",
level = 0.95,
...
)
object |
A |
new_data |
A data frame or matrix of new predictors. |
type |
A single character. The type of predictions to generate. Valid options are:
|
eval_time |
For type = "hazard" or type = "survival", the times for the distribution. |
interval |
should interval estimates be added? Options are "none" and "credible". |
level |
the tail area of the intervals. Default value is 0.95. |
... |
Not used, but required for extensibility. |
A tibble of predictions. The number of rows in the tibble is guaranteed
to be the same as the number of rows in new_data
.
Categorical predictors must be converted to factors before the fit, otherwise the predictions will fail.
# Categorical variables must be converted to factor before the fit.
require(survival)
# Wrong way of doing
set.seed(1)
mod <- survival_ln_mixture(Surv(time, status == 2) ~ factor(sex), lung, intercept = TRUE)
## Not run:
# this piece of code will throw error
predict(mod, data.frame(sex = 1), type = "survival", eval_time = 100)
## End(Not run)
# Correct way
lung$sex <- factor(lung$sex) # converting to factor before
set.seed(1)
mod2 <- survival_ln_mixture(Surv(time, status == 2) ~ sex, lung, intercept = TRUE)
# Note: the categorical predictors must be a character.
predict(mod2, data.frame(sex = "1"), type = "survival", eval_time = 100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.