rgcca_predict: Predict RGCCA

View source: R/rgcca_predict.R

rgcca_predictR Documentation

Predict RGCCA

Description

Predict a new block from a fitted RGCCA object.

Usage

rgcca_predict(
  rgcca_res,
  blocks_test = rgcca_res$call$blocks,
  prediction_model = "lm",
  metric = NULL,
  ...
)

Arguments

rgcca_res

A fitted RGCCA object (see rgcca).

blocks_test

A list of either dataframes or matrices to be projected.

prediction_model

A character giving the function used to compare the trained and the tested models.

metric

A character giving the the metric to report.

...

Additional parameters to be passed to the model fitted on top of RGCCA.

Value

A list containing the following elements:

score

the score specified by the argument metric obtained on the test block. NA if the test block is missing.

model

a list of the models trained using caret to make the predicitons and compute the metrics.

metric

a list of data.frames containing the metrics obtained on the train and test sets.

confusion

a list containing NA for regression tasks, the confusion summary produced by caret otherwise.

results

a list of lists. There is a list per column in the response block. Each list contains the score on the corresponding columns of the test response block, the learned model, predictions, confusion matrices (if classification task, NA otherwise), and additional metrics on both training and test sets. NA are reported if the test block is missing.

projection

a list of matrices containing the projections of the test blocks using the canonical components from the fitted RGCCA object. The response block is not projected.

prediction

a data.frame with the prediction of the test response block.

Examples

data("Russett")
blocks <- list(
  agriculture = Russett[, 1:3],
  industry = Russett[, 4:5],
  politic = Russett[, 6:11]
)
C <- connection <- matrix(
  c(
    0, 0, 1,
    0, 0, 1,
    1, 1, 0
  ),
  3, 3
)
object1 <- rgcca(blocks,
  connection = C, tau = c(0.7, 0.8, 0.7),
  ncomp = c(3, 2, 4), superblock = FALSE, response = 3
)
A <- lapply(object1$blocks, function(x) x[1:32, ])
object <- rgcca(A,
  connection = C, tau = c(0.7, 0.8, 0.7),
  ncomp = c(3, 2, 4),
  scale = FALSE, scale_block = FALSE,
  superblock = FALSE, response = 3
)
X <- lapply(object1$blocks, function(x) x[-c(1:32), ])
X <- lapply(X, function(x) x[, sample(1:NCOL(x))])
X <- sample(X, length(X))
response <- "industry"
y_train <- kmeans(A[[response]], 3)$cluster
y_test <- kmeans(X[[response]], 3)$cluster
res <- rgcca_predict(object, X)

Tenenhaus/RGCCA documentation built on March 16, 2023, 2:04 p.m.