Description Usage Arguments Details Value See Also Examples
Functions to extract the fitted values of models fitted via
cfboost
and make predictions for new observations.
1 2 3 4 |
object |
object of class |
newdata |
optional. a data frame in which to look for variables with which to predict. |
type |
character. Specifies the type of the returned prediction (either the hazard rate or the log hazard rate). |
... |
Further arguments to be passed to subsequent functions. |
Note that the data frame newdata needs to have the same variable names
as the original data (or as specified in the base-learners via the
xname
and zname
options).
fitted
returns a matrix of the fitted values in the last
boosting iteration of object
.
predict
can be used to make predictions on new data sets and
returns a vector of the predicted (log) hazard rates.
cfboost
for the boosting procedure and
bbs
or bols
for the specification of the base-learners.
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 | ## a simple example
set.seed(1234)
## sample covariates first
X <- matrix(NA, nrow=400, ncol=3)
X[,1] <- runif(400, -1, 1)
X[,2] <- runif(400, -1, 1)
X[,3] <- runif(400, -1, 1)
## time-dependent hazard rate
lambda <- function(time, x){
exp(0 * time + 0.7 * x[1] + x[2]^2)
}
## specify censoring function
cens_fct <- function(time, mean_cens){
censor_time <- rexp(n = length(time), rate = 1/mean_cens)
event <- (time <= censor_time)
t_obs <- apply(cbind(time, censor_time), 1, min)
return(cbind(t_obs, event))
}
data <- rSurvTime(lambda, X, cens_fct, mean_cens = 5)
ctrl <- boost_control(risk="oobag")
weights <- c(rep(1, 300), rep(0, 100))
## fit (a simple) model
model <- cfboost(Surv(time, event) ~ bbs(x.1) + bbs(x.2) + bbs(x.3),
control = ctrl, data = data, weights = weights)
## extract fitted values
fitted(model)
## make prediction for the first out-of-bag observation
predict(model, newdata = data[301,])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.