Prediction from Fitted Flexible Parametric Models

Share:

Description

Predicts the distribution function and simulates new data from a fitted model.

Usage

1
2
## S3 method for class 'flexPM'
predict(object, type = c("CDF", "QF", "sim"), newdata, p, ...)

Arguments

object

an object of class “flexPM”.

type

the type of prediction (see ‘Details’).

newdata

an optional data frame in which to look for variables with which to predict. If omitted, the model frame of the object is used.

p

the order(s) of the quantile to be computed (for type = "QF")

...

for future methods.

Details

  • If type = "CDF" (the default), the fitted cumulative distribution function (CDF) and the corresponding probability density function (PDF) and survival function (SF) are returned.

  • If type = "QF", conditional quantiles of the specified order(s) are computed.

  • If type = "sim", data are simulated from the fitted model.

New data can be supplied: observe that for type = "CDF", newdata must include the values of the response variable, and not just the covariates.

Value

  • If type = "CDF", a named data frame with variables log.f (the fitted log-PDF), log.F (the log-CDF) and log.S (the log-SF).

  • If type = "QF", a named data frame containing the fitted conditional quantiles of the specified order(s) in different columns.

  • If type = "sim", a vector of simulated data from the fitted model.

All types of prediction are computed at newdata, if supplied, or at the observed data, otherwise.

Author(s)

Paolo Frumento paolo.frumento@ki.se

See Also

flexPM

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
42
43
44
45
46
47
48
# Using simulated data

set.seed(1111); n <- 1000
x <- runif(n)
t <- rnorm(n, 1 + x, 1 + x)
model <- flexPM(Surv(t) ~ x + I(x^2)) 
# using polynomials (e.g. x^2) to achieve flexibility



# Prediction of the conditional cumulative distribution function (CDF)
# and the probability density function (PDF)

pred <- predict(model, type = "CDF") # predict the CDF and PDF

plot(pnorm(t, 1 + x, 1 + x), exp(pred$log.F))
abline(0,1, col = "green", lwd = 3) # true vs fitted CDF

plot(dnorm(t, 1 + x, 1 + x), exp(pred$log.f))
abline(0,1, col = "green", lwd = 3) # true vs fitted PDF



# Prediction of quantiles

predMe <- predict(model, type = "QF", p = 0.5) # predict the median
plot(x,t)
points(x, predMe$p0.5, col = "green") # fitted median
abline(1,1, col = "red", lwd = 3) # true median = 1 + x



# Simulate data from the fitted model

t.sim <- predict(model, type = "sim")
plot(quantile(t.sim, (1:9)/10), quantile(t, (1:9)/10)); abline(0,1)
# if the model is good, t and t.sim should have a similar distribution



######### Using new data #############################

newdata <- data.frame(t = c(0,1,2), x = c(0.1,0.5,0.9))
# note that new 't' is only needed for type = "CDF"

predict(model, type = "CDF", newdata = newdata)
predict(model, type = "QF", newdata = newdata, p = c(0.25,0.5,0.75))
predict(model, type = "sim", newdata = newdata)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.