# Setting contrasts for 10-level categorical variable

I have survey data on income and support for environmental protection. Income is a continuous variable that I have broken up into deciles. I have a hypothesis that support for protection ('Agree') will be concentrated not in the very top of the income spectrum, but in the second and third decile. So my question is how should I set the contrasts. In my mind I should compare the value of each decile to the average of all the (other?) deciles? Comparing each decile to the lowest, highest or middle won't capture what I am looking for. Helmert contrasts will get close, I think, but it would compare the first decile to the average of all below it, including the second and third, and I don't think I want that.

This is partially a question about modelling strategy and partially a question about how to implement contrasts in R. A plot of my real data is shown below the code to generate the sample data.

var1<-sample(c('A', 'B'), replace=T, size=10000)
var2<-as.factor(sample(seq(1,10,1), replace=T, size=10000))
df<-data.frame(var1=var1, var2=var2)


• What is your hypothesis? The support is higher for the average between 2nd and 3rd decile than for the average of the remaining deciles? – Sven Hohenstein Sep 12 '17 at 7:58
• That is basically it, yes. – spindoctor Sep 12 '17 at 14:51

## 1 Answer

It is seldom a good strategy to bin a continuous variable, see Why should binning be avoided at all costs?. Since you have the original income variable, you could represent it with a spline in a logistic regression model. That ought to give more effective estimation and inference.

For example, in R you could do something like

library(splines)
mod <- glm( Agree ~ ns(Income, df=5) +<other vars>,
family=binomial, data=your_data_frame, <other args> )


maybe replacing binomial with quasibinomial or some other family function.

There are alternatives like gam's (generalized additive models). A plot of estimated probability of Agree against Income (or of the estimated spline function) would be instructive. I am less sure about formal inference.