R - (Dummy Code|Categorical Variable) in Regression

Card Puncher Data Processing

About

Dummy codes in order to handle Categorical Variable

Function

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

Contrast

contrasts will give you the details of the dummy variable.

contrasts(myObject)
Red    Blue
Green     0      0
Red       1      0
Blue      0      1







Share this page:
Follow us:
Task Runner