# What are the different types of codings available for categorical variables (in R) and when would you use them?

If you fit a linear model or a mixed model there are different types of codings available to transform a categorical or nominal varibale into a number of variables for which paramaters are estimated, such as dummy conding (the R default) and effects coding.

I heard that effects coding (sometimes called deviation or contrast coding) is preferred when you have interactions, but what are the possible contrasts and when would you use which type of contrast?

The context is mixed modeling in R using lme4, but I think broader responses are fine. Sorry, if I missed a similar question.

• if you have Modern Applied Statistics with S-Plus, it has a great section in Chapter Six on this very question – richiemorrisroe May 10 '12 at 12:30
• I don't think you'll find a complete answer to your question, but there's a lot of good information about different types of codings here. – gung May 10 '12 at 13:39
• @gung The site looks really interesting. However it does not seem to cover contrast coding (or is there another name for it). – Henrik May 10 '12 at 14:24
• I'm not sure; I wonder if there's a miscommunication. The title of that page is "contrast coding". – gung May 10 '12 at 14:31
• I don't quite understand what question remains. If you wanted a list of different types of codings, you have that. What is the main thrust of your question now? – gung May 15 '12 at 17:18

Others can enlighten me if I am wrong, but here goes…

What is the effect for the level compared to the mean of the previous levels? i.e. you are interested locating the threshold of the effect

• Use Helmert contrasts. I think of this as cumulative comparisons. I have used this when interested in determining a drugs dose-response limit of the exposure. Comparison to multiple levels at a time means that less information is thrown away. I think of this as cumulative comparisons.

What is the effect of the level relative to a baseline level? i.e. you are interested in one baseline comparison group.

• Use dummy variable coding (treatment contrasts). I think of this as baseline comparisons. I have used this when there is typically one group/level established as important by other studies, and my study is demonstrating that associations also exist when this threshold is exceeded.

What is the effect of two adjacent levels of a variable?

• Use forward/backward differencing. I think of this as short-interval successive comparisons. I have used this when comparing effects for different levels of socioeconomic position, when each group is compositionally different in their own right and no more of interest than any other.