Description Usage Arguments Details Value Examples
View source: R/predict_cmfit.R
Obtain predictions and confidence intervals for the hazard function or the time to event from a fitted cyclomort object.
1 2 3 4 5 6 7 8 9 10 |
object |
a cmfit object |
... |
(not implemented) |
t |
times for prediction. By default, covers 100 observations over a single period. |
type |
either |
CI |
a boolean dictating whether or not to compute confidence intervals |
CI.level |
confidence level (default 0.95) for CIs (if CI is TRUE) |
nreps |
number of samples drawn to generate confidence intervals. The default 10^3 is generally sufficient, and very fast for the hazard function, but possibly prohibitively slow for the time-to-event functionality. |
Confidence intervals are produced by sampling from the multivariate normal distribution of the MLE parameter estimates accounting for the covariance in the estimates by using the Hessian of the MLE.
a list of vectors containing predictions for each value in t
,
as well as (optional) confidence intervals.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # simulate two-peak mortality process
sim.morts <- simulate_cycloSurv(300, period = 1, peaks = c(0.3, 0.8),
durations = c(0.15, 0.20), weights = c(3, 2)/5,
meanhazard = 1, plotme = FALSE, max.periods = 6)
sim.morts <- simulate_cycloSurv(300, period = 365, peaks = c(0.3, 0.8)*365,
durations = c(0.15, 0.20)*365, weights = c(3, 2)/5,
meanhazard = 1/365, plotme = FALSE, max.periods = 6)
# estimate parameters
sim.morts.fit <- fit_cyclomort(sim.morts, n.seasons = 2)
# compute predictions for one moment in time (with 95% confidence interval)
predict(sim.morts.fit, CI = TRUE, type = "hazard")
# compute predictions for a range of times
predict(sim.morts.fit, t = 1:365, CI = FALSE, type = "hazard")
# these predictions are used (internally) in the plot.cmfit method:
plot(sim.morts.fit, CI.level = 0.95, months = FALSE, histogram = FALSE, monthlabs = TRUE)
plot(sim.morts.fit, CI.level = 0.8, months = FALSE, histogram = FALSE, add = TRUE)
plot(sim.morts.fit, CI.level = 0.5, months = FALSE, histogram = FALSE, add = TRUE)
# predict time to event given a start at times (this is a very slow calculation!)
timetoeventprediction <- predict(sim.morts.fit, t = seq(1,365,3), type = "timetoevent",
CI = TRUE, nreps = 1e2)
# the following object contains a prediction
data(timetoeventprediction)
with(timetoeventprediction, {
plot(t, fit, type = "l", lwd = 2, main = "expected time to event",
ylim = c(100,365), ylab = "days")
lines(t, CI[1,], lty = 3)
lines(t, CI[2,], lty = 3)
})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.