predict.covregrf {CovRegRF}R Documentation

Predict method for covregrf objects

Description

Obtain predicted covariance matrices using a covregrf forest for training or new data.

Usage

## S3 method for class 'covregrf'
predict(object, newdata, ...)

Arguments

object

An object of class (covregrf, grow) created by the function covregrf.

newdata

Test data of the set of covariates. A data.frame with numeric values and factors. If missing, the out-of-bag predictions in object is returned.

...

Optional arguments to be passed to other methods.

Value

An object of class (covregrf, predict) which is a list with the following components:

predicted

Predicted covariance matrices for test data. If newdata is missing, OOB predictions for training observations.

bop

Bag of Observations for Prediction. An nxn matrix of counts.

n

Sample size of the test data (NA's are omitted). If newdata is missing, sample size of the training set.

xvar.names

A character vector of the covariate names.

yvar.names

A character vector of the response variable names.

See Also

covregrf vimp.covregrf print.covregrf

Examples


## load generated example data
data(data, package = "CovRegRF")
xvar.names <- colnames(data$X)
yvar.names <- colnames(data$Y)
data1 <- data.frame(data$X, data$Y)

## define train/test split
set.seed(2345)
smp <- sample(1:nrow(data1), size = round(nrow(data1)*0.6), replace = FALSE)
traindata <- data1[smp,,drop=FALSE]
testdata <- data1[-smp, xvar.names, drop=FALSE]

## formula object
formula <- as.formula(paste(paste(yvar.names, collapse="+"), ".", sep=" ~ "))

## train covregrf
covregrf.obj <- covregrf(formula, traindata, params.rfsrc = list(ntree = 50))

## predict without new data (OOB predictions will be returned)
pred.obj <- predict(covregrf.obj)
pred.oob <- pred.obj$predicted

## predict with new test data
pred.obj2 <- predict(covregrf.obj, newdata = testdata)
pred <- pred.obj2$predicted


[Package CovRegRF version 1.0.1 Index]