predict.cfboost: Predictions (for New Observations)

Description Usage Arguments Details Value See Also Examples

View source: R/methods.R

Description

Functions to extract the fitted values of models fitted via cfboost and make predictions for new observations.

Usage

1
2
3
4
## S3 method for class 'cfboost'
fitted(object, type = c("hazard", "log-hazard"), ...)
## S3 method for class 'cfboost'
predict(object, newdata = NULL, type = c("hazard", "log-hazard"), ...)

Arguments

object

object of class cfboost.

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.

Details

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

Value

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.

See Also

cfboost for the boosting procedure and bbs or bols for the specification of the base-learners.

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
## 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,])

CoxFlexBoost documentation built on May 2, 2019, 6:53 p.m.