predict.fusedTree {fusedTree} | R Documentation |
Predict Method for Fused Tree Models
Description
Generates predictions from a fitted fusedTree
object using new clinical and omics data.
Usage
## S3 method for class 'fusedTree'
predict(object, newX, newZ, newY, ...)
Arguments
object |
An object of class |
newX |
A matrix of new omics covariates for prediction. Must have the same number of columns (variables) as used in the model fitting. |
newZ |
A data frame of new clinical covariates for prediction. |
newY |
A numeric response vector or a |
... |
Currently not used. Included for S3 method consistency. |
Value
A model-specific prediction object:
For
"linear"
models: adata.frame
with columnsResp
(observed responses) andYpred
(predicted values).For
"logistic"
models: adata.frame
with columnsResp
(observed labels),Ypred
(predicted probabilities), andLinPred
(linear predictor).For
"cox"
models: alist
with two elements:- data
A
data.frame
with columnsResp
(aSurv
object) andLinPred
.- Survival
A matrix of predicted survival probabilities. Rows = test subjects, columns = unique times from
newY
.
See Also
fusedTree
for model fitting.
Examples
p = 5 # number of omics variables (low for illustration)
p_Clin = 5 # number of clinical variables
N = 100 # sample size
# simulate from Friedman-like function
g <- function(z) {
15 * sin(pi * z[,1] * z[,2]) + 10 * (z[,3] - 0.5)^2 + 2 * exp(z[,4]) + 2 * z[,5]
}
set.seed(11)
Z <- as.data.frame(matrix(runif(N * p_Clin), nrow = N))
X <- matrix(rnorm(N * p), nrow = N) # omics data
betas <- c(1,-1,3,4,2) # omics effects
Y <- g(Z) + X %*% betas + rnorm(N) # continuous outcome
Y <- as.vector(Y)
dat = cbind.data.frame(Y, Z) #set-up data correctly for rpart
rp <- rpart::rpart(Y ~ ., data = dat,
control = rpart::rpart.control(xval = 5, minbucket = 10),
model = TRUE)
cp = rp$cptable[,1][which.min(rp$cptable[,4])] # best model according to pruning
Treefit <- rpart::prune(rp, cp = cp)
fit <- fusedTree(Tree = Treefit, X = X, Y = Y, Z = Z,
LinVars = FALSE, model = "linear",
lambda = 10,
alpha = 1000)
Preds <- predict(fit, newX = X, newZ = Z, newY = Y)