Description Usage Arguments Details Value References See Also Examples
View source: R/add_quantile_survreg.R
This function is one of the methods of add_quantile
and is
automatically called when an object of class survreg
is
passed to add_quantile
.
1 2 3 4 5 6 7 8 9 10 11 |
df |
A data frame of new data. |
fit |
An object of class |
p |
A real number between 0 and 1. Sets the probability level of the quantiles. |
name |
|
yhatName |
A string. Name of the vector of predictions. |
confint |
A logical. If |
alpha |
A number. Controls the confidence level of the
confidence intervals if |
... |
Additional arguments. |
add_quantile.survreg
produces quantiles for the estimated
distribution of survival times from a survreg object. Estimated
quantiles (such as the median survival time) may be calculated for
a range of distributions including lognormal, exponential, weibull,
and loglogistic models. add_quantile.survreg
can compute
quantiles through a parametric method based on the Delta
Method. Generally, this method performs well under a mild to
moderate amount of censoring. Parametric intervals are calculated
using a transformation of the confidence intervals produced by
predict.survreg
and are mathematically identical to intervals
calculated by a manual Delta Method.
Unlike other add_quantile
methods,
add_quantile.survreg
additionally produces confidence
intervals for predicted quantiles by default. This may optionally
be disabled by switching the confint
argument.
Note: Due to a limitation, the Surv
object must be specified in
survreg
function call. See the examples section for one way
to do this.
Note: add_quantile.survreg
cannot inspect the convergence of
fit
. Poor maximum likelihood estimates will result in poor
confidence intervals. Inspect any warning messages given from
survreg
.
A dataframe, df
, with predicted medians, level p
quantiles, and confidence intervals attached.
For descriptions of the log-location scale models supported: Meeker, William Q., and Luis A. Escobar. Statistical methods for reliability data. John Wiley & Sons, 2014. (Chapter 4)
For a description of the multivariate Delta method: Meeker, William Q., and Luis A. Escobar. Statistical methods for reliability data. John Wiley & Sons, 2014. (Appendix B.2)
For a description of Delta Method Confidence Intervals: Meeker, William Q., and Luis A. Escobar. Statistical methods for reliability data. John Wiley & Sons, 2014. (Chapter 8)
add_ci.survreg
for confidence intervals
survreg
objects, add_pi.survreg
for
prediction intervals of survreg
objects, and
add_probs.survreg
for survival probabilities of
survreg
objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Define a data set:
df <- survival::stanford2
## remove a covariate with missing values:
df <- df[, 1:4]
## next, create the Surv object inside the survreg call:
fit <- survival::survreg(survival::Surv(time, status) ~ age + I(age^2),
data = df, dist = "lognormal")
## Calculate the level 0.75 quantile wit CIs for that quantile
add_quantile(df, fit, p = 0.75, name = c("quant", "lwr", "upr"))
## Try a weibull model for the same data:
fit2 <- survival::survreg(survival::Surv(time, status) ~ age + I(age^2),
data = df, dist = "weibull")
## Calculate the level 0.75 quantile with CIs for the quantile
add_quantile(df, fit2, p = 0.75, name = c("quant", "lwr", "upr"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.