Description Usage Arguments Details Value Author(s) See Also Examples
Predicts the distribution function and simulates new data from a fitted model.
1 2 |
object |
an object of class “ |
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 |
... |
for future methods. |
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.
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.
Paolo Frumento paolo.frumento@ki.se
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.