predict.cmfit: Prediction method for cyclomort fits

Description Usage Arguments Details Value Examples

View source: R/predict_cmfit.R

Description

Obtain predictions and confidence intervals for the hazard function or the time to event from a fitted cyclomort object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'cmfit'
predict(
  object,
  ...,
  t = seq(0, object$period, length = 500),
  type = "hazard",
  CI = FALSE,
  CI.level = 0.95,
  nreps = 1000
)

Arguments

object

a cmfit object

...

(not implemented)

t

times for prediction. By default, covers 100 observations over a single period.

type

either hazard or timetoevent - dictates what exactly will be predicted

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.

Details

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.

Value

a list of vectors containing predictions for each value in t, as well as (optional) confidence intervals.

Examples

 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)
})

cyclomort documentation built on Aug. 20, 2020, 5:06 p.m.