predict.rfcca: Predict method for rfcca objects

View source: R/predict.rfcca.R

predict.rfccaR Documentation

Predict method for rfcca objects

Description

Obtain predicted canonical correlations using a rfcca forest for training or new data.

Usage

## S3 method for class 'rfcca'
predict(
  object,
  newdata,
  membership = FALSE,
  finalcca = c("cca", "scca", "rcca"),
  ...
)

Arguments

object

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

newdata

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

membership

Should terminal node membership information be returned?

finalcca

Which CCA should be used for final canonical correlation estimation? Choices are cca, scca and rcca, see rfcca for details. The default is cca.

...

Optional arguments to be passed to other methods.

Value

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

call

The original grow call to rfcca.

n

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

ntree

Number of trees grown.

xvar

Data frame of x-variables.

xvar.names

A character vector of the x-variable names.

yvar

Data frame of y-variables.

yvar.names

A character vector of the y-variable names.

zvar

Data frame of test z-variables. If newdata is missing, data frame of training z-variables.

zvar.names

A character vector of the z-variable names.

forest

The (rfcca,grow) forest.

membership

A matrix recording terminal node membership for the test data where each cell represents the node number that an observation falls in for that tree.

predicted

Test set predicted canonical correlations based on the selected final canonical correlation estimation method. If newdata is missing, OOB predictions for training observations.

predicted.coef

Predicted canonical weight vectors for x- and y- variables.

finalcca

The selected CCA used for final canonical correlation estimations.

See Also

rfcca vimp.rfcca print.rfcca

Examples


## load generated example data
data(data, package = "RFCCA")
set.seed(2345)

## define train/test split
smp <- sample(1:nrow(data$X), size = round(nrow(data$X) * 0.7),
  replace = FALSE)
train.data <- lapply(data, function(x) {x[smp, ]})
test.Z <- data$Z[-smp, ]

## train rfcca
rfcca.obj <- rfcca(X = train.data$X, Y = train.data$Y, Z = train.data$Z,
  ntree = 100)

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

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

## print predict objects
print(pred.obj)
print(pred.obj2)



RFCCA documentation built on Sept. 19, 2023, 9:06 a.m.