Pre-Processing of Predictors

Pre-processing transformation (centering, scaling etc) can be estimated from the training data and applied to any data set with the same variables.

preProcess(x, ...)

## S3 method for class 'default': preProcess(x, method = c("center", "scale"), thresh = 0.95, na.remove = TRUE, k = 5, knnSummary = mean, outcome = NULL, fudge = .2, numUnique = 3, verbose = FALSE, ...)

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

a matrix or data frame. All variables must be numeric.
a character vector specifying the type of processing. Possible values are "BoxCox", "center", "scale", "range", "knnImpute", "bagImpute", "pca" "ica" and "spatialSign" (see Details below)
a cutoff for the cumulative percent of variance to be retained by PCA
a logical; should missing values be removed from the calculations?
an object of class preProcess
a matrix or data frame of new data to be pre-processed
the number of nearest neighbors from the training set to use for imputation
function to average the neighbor values per column during imputation
a numeric or factor vector for the training set outcomes. This can be used to help estimate the Box-Cox transformation of the predictor variables (see Details below)
a tolerance value: Box-Cox transformation lambda values within +/-fudge will be coerced to 0 and within 1+/-fudge will be coerced to 1
how many unique values should y have to estimate the Box-Cox transformation?
a logical: prints a log as the computations proceed
additional arguments to pass to fastICA, such as n.comp

The Box-Cox transformation has been "repurposed" here: it is being used to transform the predictor variables. This method was developed for transforming the response variable while another method, the Box-Tidwell transformation, was created to estimate transformations of predictor data. However, the Box-Cox method is simpler, more computationally efficient and is equally effective for estimating power transformations.

The "range" transformation scales the data to be within [0, 1]. If new samples have values larger or smaller than those in the training set, values will be outside of this range.

The operations are applied in this order: Box-Cox transformation, centering, scaling, range, imputation, PCA, ICA then spatial sign. This is a departure from versions of caret prior to version 4.76 (where imputation was done first) and is not backwards compatible if bagging was used for imputation.

If PCA is requested but centering and scaling are not, the values will still be centered and scaled. Similarly, when ICA is requested, the data are automatically centered and scaled.

k-nearest neighbor imputation is carried out by finding the k closest samples (Euclidian distance) in the training set. Imputation via bagging fits a bagged tree model for each predictor (as a function of all the others). This method is simple, accurate and accepts missing values, but it has much higher computational cost.

A warning is thrown if both PCA and ICA are requested. ICA, as implemented by the fastICA package automatically does a PCA decomposition prior to finding the ICA scores.

The function will throw an error of any variables in x has less than two unique values.


  • preProcess results in a list with elements
  • callthe function call
  • dimthe dimensions of x
  • bcBox-Cox transformation values, see BoxCoxTrans
  • meana vector of means (if centering was requested)
  • stda vector of standard deviations (if scaling or PCA was requested)
  • rotationa matrix of eigenvectors if PCA was requested
  • methodthe value ofmethod
  • threshthe value ofthresh
  • rangesa matrix of min and max values for each predictor when method includes "range" (and NULL otherwise)
  • numCompthe number of principal components required of capture the specified amount of variance
  • icacontains values for the W and K matrix of the decomposition


Kuhn (2008), ``Building Predictive Models in R Using the caret'' (

Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations (with discussion). Journal of the Royal Statistical Society B, 26, 211-252.

Box, G. E. P. and Tidwell, P. W. (1962) Transformation of the independent variables. Technometrics 4, 531-550.

See Also

BoxCoxTrans, boxcox, prcomp, fastICA, spatialSign

  • preProcess
  • preProcess.default
  • predict.preProcess
# one variable has one unique value
preProc <- preProcess(bbbDescr[1:100,])

preProc <- preProcess(bbbDescr[1:100,-3])
training <- predict(preProc, bbbDescr[1:100,-3])
test <- predict(preProc, bbbDescr[101:208,-3])
Documentation reproduced from package caret, version 4.87, License: GPL-2

Community examples

Looks like there are no examples yet.