# Indicator variable for binary data: {-1,1} vs {0,1}

I am interested in treatment-covariate interactions in the context of experiments/randomized controlled trials, with a binary treatment assignment indicator $T$.

Depending on the specific method/ source, I have seen both $T=\{1,0\}$ and $T=\{1, -1\}$ for the treated and the untreated subjects, respectively.

Is there any rule of thumb when to use $\{1,0\}$ or $\{1, -1\}$?

In what way does the interpretation differ?

The interpretation of both the estimator of the indicator variable and the intercept differ. Let's start with $\{1,0\}$:

Say you have the following model

$$y_i = \beta_0 + treatment\cdot\beta_1$$

where

$$treatment = \begin{cases} 0 & \text{if placebo} \\ 1 & \text{if drug} \end{cases}$$

In that case you end up with the following formulas for $y_i$:

$$y_i = \begin{cases} \beta_0 + 0\cdot\beta_1 = \beta_0 & \text{if placebo} \\ \beta_0 + 1\cdot\beta_1 = \beta_0 + \beta_1 & \text{if drug} \end{cases}$$

So the interpretation of $\beta_0$ is the effect of the placebo and the interpretation of $\beta_1$ is the difference between the effect of the placebo and the effect of the drug. In effect, you can interpret $\beta_1$ as the improvement that the drug offers.

Now let's look at $\{-1,1\}$:

You then have the following model (again):

$$y_i = \beta_0 + treatment\cdot\beta_1$$

but where

$$treatment = \begin{cases} -1 & \text{if placebo} \\ 1 & \text{if drug} \end{cases}$$

In that case you end up with the following formulae for $y_i$:

$$y_i = \begin{cases} \beta_0 + -1\cdot\beta_1 = \beta_0 - \beta_1& \text{if placebo} \\ \beta_0 + 1\cdot\beta_1 = \beta_0 + \beta_1 & \text{if drug} \end{cases}$$

The interpretation here is that $\beta_0$ is the mean of the placebo's effect and the drug's effect, and $\beta_1$ is the difference of the two treatments to that mean.

### So which do you use?

The interpretation of $\beta_0$ in $\{0,1\}$ is basically a baseline. You set some standard treatment and all the other treatments (there can be multiple) are compared with that standard/baseline. Especially when you start adding in other covariates this remains easy to interpret with regards to the standard medical question: how do these drugs compare with a placebo or the established drug?

But in the end it is all a matter of interpretation, which I explained above. So you should evaluate your hypotheses and check which interpretation makes the drawing of conclusions the most straightforward.

• The constant when using the -1, 1 coding is the mean iff the number of respondents in the treated group is the same as the number of respondents in the control group. – Maarten Buis Nov 5 '16 at 10:58
• @MaartenBuis It is the mean of $y$ iff the design is balanced, but otherwise it still is the mean of the two group means, which is what I meant. I changed the wording to reflect this. – JAD Nov 5 '16 at 11:09
• Helpful. I always try to encourage use of the word indicator rather than dummy (as in the original question!) for at least two reasons. First, I have heard too many stories in which presentations went down very badly because terms such as "gender dummy" were wildly misinterpreted as disparaging or offensive by less technical people. Second, the term dummy makes the whole device seem a little like a fudge or a dodge, whereas it is a perfectly clean and elegant method. I don't have much chance of changing entrenched practices in some fields, but here's trying. – Nick Cox Nov 5 '16 at 11:33
• Agreed, it sounds more professional as well. Plus it is a better description of what it is actually doing. – JAD Nov 5 '16 at 11:37
• Glad you agree. Here is a simple way to explain: it's called an indicator because it indicates! – Nick Cox Nov 5 '16 at 11:41

In the context of linear regression, $x_i \in \{0, 1\}$ is more natural (and standard) method for coding binary variables (whether placing them on the left-hand side of right-hand side of the regression). As @Jarko Dubbeldam explains, you can of course use the other interpretation and the meaning of the coefficients will be different.

To give an example the other way, coding output variables $y_i \in \{-1, 1\}$ is standard when programming or deriving the math underlying support vector machines. (When calling libraries, you want to pass the data in the format the library expects, which is probably the 0, 1 formulation.)

Try to use the notation that is standard for whatever you are doing/using.

For any kind of linear model with an intercept term, the two methods will be equivalent in the sense that they're related by a simple linear transformation. Mathematically, it doesn't matter whether you use data matrix $X$ or data matrix $\tilde{X} = XA$ where $A$ is full rank. In generalized linear models, your estimated coefficients either way will be related by the linear transformation $A$ and the fitted values $\hat{y}$ will be the same.

• +1, I couldn't think of a setting where $\{-1,1\}$ was used. – JAD Nov 5 '16 at 11:02
• AdaBoost is another example that uses $y_i\in\{-1,1\}$ – Francis Nov 5 '16 at 11:43
• In general, you could say that $\{-1,1\}$ is used predominantly in classification, because it makes applying the sign function a feasible way to classify. – JAD Nov 5 '16 at 11:53
• @matthewgunn The author is talking the covariates, i.e., the inputs not the outputs. The {-1, 1} makes sense for support vectors for the output but it doesn't matter for the input. See here: en.wikipedia.org/wiki/Support_vector_machine#Linear_SVM – Francisco Arceo Nov 7 '16 at 13:41
• @FranciscoArceo Point taken; I've edited to be more precise. – Matthew Gunn Nov 7 '16 at 18:16

This is more abstract (and perhaps useless), but I'll note that these two representations are, in a mathematical sense, actually group representations, and there is a isomorphism between them.

The meaning of the indicator variable $T$, at heart a boolean, is "factor is true" or "factor is false". Given two events $T_1$ and $T_2$, you might ask "are the factors of these two events equivalent, e.g. are they either both true or both false?" In boolean logic this is $T_1 \Leftrightarrow T_2$. This defines a group structure $\mathbb{Z}_2$. Now, ${1,0}$ and ${1,-1}$ both form representations of this group, with the group operations $a \Leftrightarrow b = 1 - (a+b)$ and $a \Leftrightarrow b = ab$, respectively. The isomorphism from the first representation to the second is given by $\phi(a) = 2*a-1$.

This representation also extends to continuous indicator variables, i.e. probabilities. If $p$ is the probability for $T$ to be true, then the probability for $T \Leftrightarrow T'$ to be true is $p' \Leftrightarrow p = pp' + (1-p)(1-p')$. Under the isomorphism $t(p) = 2p-1$, this is $t \Leftrightarrow t' = tt'$. The quantity $t$ is a signed indicator between -1 and 1. So, calculations about probabilities of boolean operations are often much simpler in this basis.

• This is impressive, but I find it sufficient to remark that any valid correspondence between {-1, 1} and {0, 1} must be one to one: there is no need for invoke anything beyond high school mathematics. We're necessarily talking about the same information, just coded differently. – Nick Cox Nov 7 '16 at 17:56