I have a data set that contains both categorical variables and continuous variables. I was advised to transform the categorical variables as binary variables for each level (ie, A_level1:{0,1}, A_level2:{0,1}) - I think some have called this "dummy variables".

With that said, would it be misleading to then center and scale the entire data set with the new variables? It seems as if I would lose the "on/off" meaning of the variables.

If it is misleading, does that mean I should center and scale the continuous variables separately and then re-add it to my data set?

TIA.

  • 1
    Whether it is acceptable or reasonable to center and/or scale dummy variables depends on the application, on the analysis you are planning and task-specific considerations. So there is no single correct answer. In most general, rough formulation, it is often ok to do it with predictor dummy variables; it is often a bad idea to to it with response dummy variables or in multivariate methods such as clustering or factor analysis. – ttnphns Aug 30 '17 at 15:35
up vote 8 down vote accepted

When constructing dummy variables for use in regression analyses, each category in a categorical variable except for one should get a binary variable. So you should have e.g. A_level2, A_level3 etc. One of the categories should not have a binary variable, and this category will serve as the reference category. If you don't omit one of the categories, your regression analyses won't run properly.

If you use SPSS or R, I don't think the scaling and centering of the entire data set will generally be a problem since those software packages often interprets variables with only two levels as factors, but it may depend on the specific statistical methods used. In any case, it makes no sense to scale and center binary (or categorical) variables so you should only center and scale continuous variables if you must do this.

  • My strong feeling is that the only part of the answer that is really answering the OP question is that last sentence - an that part being unexplained. You say don't scale them but don't explain why. Meanwhile, the topic is not very easy. – ttnphns Sep 1 '17 at 8:00

If you are using R and scaling the dummy variables or variables having 0 or 1 to a scale between 0 and 1 only, then there won't be any change on the values of these variables, rest of the columns will be scaled.

maxs <- apply(data, 2, max) 
mins <- apply(data, 2, min)

data.scaled <- as.data.frame(scale(data, center = mins, scale = maxs - mins))
  • Interesting tip. Thank you for sharing. It's been awhile since I asked, but good to see I can still learn from these old posts. – user2300643 Aug 31 '17 at 22:33

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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