Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

In some literature, I have read that a regression with multiple explanatory variables, if in different units, needed to be standardized. (Standardizing consists in subtracting the mean and dividing by the standard deviation.) In which other cases do I need to standardize my data? Are there cases in which I should only center my data (i.e., without dividing by standard deviation)?

share|improve this question
2  
A related post in Andrew Gelman's blog. – user10525 Jun 4 '12 at 18:45
3  
In addition to the great answers already given, let me mention that when using penalization methods such as ridge regression or lasso the result is no longer invariant to standardization. It is, however, often recommended to standardize. In this case not for reasons directly related to interpretations, but because the penalization will then treat different explanatory variables on a more equal footing. – NRH Jun 5 '12 at 7:42
1  
Welcome to the site @mathieu_r! You've posted two very popular questions. Please consider upvoting/accepting some of the excellent answers you've received to both questions ;) – Macro Jun 5 '12 at 20:41

5 Answers

In regression, it is often recommended to center the variables so that the predictors have mean $0$. This makes it so the intercept term is interpreted as the expected value of $Y_i$ when the predictor values are set to their means. Otherwise, the intercept is interpreted as the expected value of $Y_i$ when the predictors are set to 0, which may not be a realistic or interpretable situation (e.g. what if the predictors were height and weight?). Another practical reason for scaling in regression is when one variable has a very large scale, e.g. if you were using population size of a country as a predictor. In that case, the regression coefficients may on be a very small order of magnitude (e.g. $10^{-6}$) which can be a little annoying when you're reading computer output, so you may convert the variable to, for example, population size in millions. The convention that you standardize predictions primarily exists so that the units of the regression coefficients are the same.

As @gung alludes to and @MÃ¥nsT shows explicitly (+1 to both, btw), centering/scaling does not effect your statistical inference in regression models - the estimates are adjusted appropriately and the $p$-values will be the same.

Other situations where centering and/or scaling may be useful:

  • when you're trying to sum or average variables that are on different scales, perhaps to create a composite score of some kind. Without scaling, it may be the case that one variable has a larger impact on the sum due purely to its scale, which may be undesirable.

  • To simplify calculations and notation. For example, the sample covariance matrix of a matrix of values centered by their sample means is simply $X'X$. Similarly, if a univariate random variable $X$ has been mean centered, then ${\rm var}(X) = E(X^2)$ and the variance can be estimated from a sample by looking at the sample mean of the squares of the observed values.

  • Related to aforementioned, PCA can only be interpreted as the singular value decomposition of a data matrix when the columns have first been centered by their means.

Note that scaling is not necessary in the last two bullet points I mentioned and centering may not be necessary in the first bullet I mentioned, so the two need to go hand and hand at all times.

share|improve this answer
1  
+1, these are good points I didn't think of. For clarity, let me list some concrete examples where a researcher might want to combine explanatory variables prior to running a regression, & thus need to standardize. One case might be for research into children's behavioral disorders; researchers might get ratings from both parents & teachers, & then want to combine them into a single measure of maladjustment. Another case could be a study on the activity level at a nursing home w/ self-ratings by residents & the number of signatures on sign-up sheets for activities. – gung Jun 4 '12 at 18:15
1  
Ten edits in 8 hours? ;-) – cardinal Jun 5 '12 at 2:02
1  
It's like simulated annealing @cardinal! I was making uphill steps. Also, I find I have a bad habit of barely missing the time window (around 5 minutes I think it is) where it doesn't count as a new edit :) – Macro Jun 5 '12 at 2:24
2  
But shouldn't we in theory use the population mean and standard deviation for centering/scaling? In practice, is it as simple as using the sample mean/SD or is there more to it? – AlefSin Jun 5 '12 at 8:18
1  
@AlefSin: you may actually want to use something else than the population mean/sd, see my answer. But your point that we should think what to use for centering/scaling is very good. – cbeleites Jun 5 '12 at 11:06
show 5 more comments

You have come across a common belief. However, in general, you do not need to center or standardize your data for multiple regression. Different explanatory variables are almost always on different scales (i.e., measured in different units). This is not a problem; the betas are estimated such that they convert the units of each explanatory variable into the units of the response variable appropriately. One thing that people sometimes say is that if you have standardized your variables first, you can then interpret the betas as measures of importance. For instance, if $\beta_1=.6$, and $\beta_2=.3$, then the first explanatory variable is twice as important as the second. While this idea is appealing, unfortunately, it is not valid. There are several issues, but perhaps the easiest to follow is that you have no way to control for possible range restrictions in the variables. Inferring the 'importance' of different explanatory variables relative to each other is a very tricky philosophical issue. None of that is to suggest that standardizing is bad or wrong, just that it typically isn't necessary.

The only case I can think of off the top of my head where centering is helpful is before creating power terms. Lets say you have a variable, $X$, that ranges from 1 to 2, but you suspect a curvilinear relationship with the response variable, and so you want to create an $X^2$ term. If you don't center $X$ first, your squared term will be highly correlated with $X$, which could muddy the estimation of the beta. Centering first addresses this issue.

share|improve this answer
1  
If anyone is interested, I also talk about the mistaken idea of using standardized betas to infer relative 'importance' here: multiple-linear-regression-for-hypothesis-testing – gung Sep 15 '12 at 4:05

In addition to the remarks in the other answers, I'd like to point out that the scale and location of the explanatory variables does not affect the validity of the regression model in any way.

Consider the model $y=\beta_0+\beta_1x_1+\beta_2x_2+\ldots+\epsilon$.

The least squares estimators of $\beta_1, \beta_2,\ldots$ are not affected by shifting. The reason is that these are the slopes of the fitting surface - how much the surface changes if you change $x_1,x_2,\ldots$ one unit. This does not depend on location. (The estimator of $\beta_0$, however, does.)

By looking at the equations for the estimators you can see that scaling $x_1$ with a factor $a$ scales $\hat{\beta}_1$ by a factor $1/a$. To see this, note that

$$\hat{\beta}_1(x_1)=\frac{\sum_{i=1}^n(x_{1,i}-\bar{x}_1)(y_i-\bar{y})}{\sum_{i=1}^n(x_{1,i}-\bar{x}_1)^2}.$$

Thus

$$\hat{\beta}_1(ax_1)=\frac{\sum_{i=1}^n(ax_{1,i}-a\bar{x}_1)(y_i-\bar{y})}{\sum_{i=1}^n(ax_{1,i}-a\bar{x}_1)^2}=\frac{a\sum_{i=1}^n(x_{1,i}-\bar{x}_1)(y_i-\bar{y})}{a^2\sum_{i=1}^n(x_{1,i}-\bar{x}_1)^2}=\frac{\hat{\beta}_1(x_1)}{a}.$$

By looking at the corresponding formula for $\hat{\beta}_2$ (for instance) it is (hopefully) clear that this scaling doesn't affect the estimators of the other slopes.

Thus, scaling simply corresponds to scaling the corresponding slopes.

As gung points out, some people like to rescale by the standard deviation in hopes that they will be able to interpret how "important" the different variables are. While this practice can be questioned, it can be noted that this corresponds to choosing $a_i=1/s_i$ in the above computations, where $s_i$ is the standard deviation of $x_1$ (which in a strange thing to say to begin with, since the $x_i$ are assumed to be deterministic).

share|improve this answer
+1, very clearly explained. – gung Jun 4 '12 at 17:15

I prefer "solid reasons" for both centering and standardization (they exist very often). In general, they have more to do with the data set and the problem than with the data analysis method.

Very often, I prefer to center (i.e. shift the origin of the data) to other points that are physically/chemically/biologically/... more meaningful than the mean (see also Macro's answer), e.g.

  • the mean of a control group

  • blank signal

Numerical stability is an algorithm-related reason to center and/or scale data.

Also, have a look at the similar question about standardization. Which also covers "center only".

share|improve this answer

In case you use gradient descent to fit your model, standardizing covariates may speed up convergence (because when you have unscaled covariates, the corresponding parameters may inappropriately dominate the gradient). To illustrate this, some R code:

> objective <- function(par){ par[1]^2+par[2]^2}  #quadratic function in two variables with a minimum at (0,0)
> optim(c(10,10), objective, method="BFGS")$counts  #returns the number of times the function and its gradient had to be evaluated until convergence
    function gradient 
          12        3 
> objective2 <- function(par){ par[1]^2+0.1*par[2]^2}  #a transformation of the above function, corresponding to unscaled covariates
> optim(c(10,10), objective2, method="BFGS")$counts
function gradient 
      19       10 
> optim(c(10,1), objective2, method="BFGS")$counts  #scaling of initial parameters doesn't get you back to original performance
function gradient 
      12        8

Also, for some applications of SVMs, scaling may improve predictive performance: Feature scaling in support vector data description.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.