predict.comfam function

Apply Harmonization to New Data

Apply Harmonization to New Data

Using parameters estimated via comfam, apply harmonization on new data. predict.comfam will estimate new batch adjustments if new batches are specified. For batches with existing estimates, the estimates from object

are used. Harmonization targets are the same as object (e.g. ref.batch

from object if specified).

## S3 method for class 'comfam' predict( object, newdata, newbat, newcovar = NULL, robust.LS = FALSE, eb = TRUE, ... )

Arguments

  • object: Object of class comfam, typically output of the harmonization function in this package.
  • newdata: n x p data frame or matrix of new observations where p is the number of features and n is the number of subjects. The features must match the original data used in object
  • newbat: Factor indicating new batch (often equivalent to site or scanner)
  • newcovar: Data frame or matrix of new covariates supplied to model. Must contain all variables specified in the original formula used in object.
  • robust.LS: If TRUE, uses robust location and scale estimators for new batch effect estimates Currently uses median and biweight midvariance
  • eb: If TRUE, uses ComBat model with empirical Bayes for new batches
  • ...: Additional arguments to predict for the class of model (e.g. predict.lm for ComBat)

Returns

predict.comfam returns a list containing the following components: - dat.combat: New harmonized data as a matrix with same dimensions as newdata

  • batch.info: New batch information, including reference batch if specified

  • fits: List of model fits from regression step, forwarded from object

  • estimates: List of estimates from standardization and batch effect correction, including new batches if relevant

Details

Note: The function currently does not support models of class lmer

(e.g., from lmer ).

Examples

com_out <- comfam(iris[1:75,1:2], iris$Species[1:75]) # out-of-sample with new batch out_pred <- predict(com_out, iris[76:150,1:2], iris$Species[76:150]) # in-sample in_pred <- predict(com_out, iris[1:25,1:2], iris$Species[1:25]) max(in_pred$dat.combat - com_out$dat.combat[1:25,])