R - (Dummy Code|Categorical Variable) in Regression

> Procedural Languages > R

1 - About

Dummy codes in order to handle Categorical Variable

3 - Function

3.1 - C

  • With a categorical predictor, dummy codes to represent the nominal variable as numeric using the function C (for contrasts)
myCategoricalPredictor <- C(data$CategoricalPredictor, treatment)
model <- lm(data$OutcomeVariable ~ data$NumericPredictorVariable + myCategoricalPredictor)

? This is not always needed as R will do it for you

Advertising

3.2 - Contrast

contrasts will give you the details of the dummy variable.

contrasts(myObject)
       Red    Blue
Green     0      0
Red       1      0
Blue      0      1
lang/r/dummy.txt · Last modified: 2017/02/12 21:02 by gerardnico