The problem is that you have several misunderstandings about logistic regression and the representation of categorical data in regression models. First, we don't generally think of there being an error term in logistic regression1, so the "$e$" in your description of your model should not be there. (Also, since the predictor is a multi-level categorical variable, $\bf X$ will have to be a row vector and the $\rm coefficient$ will have to be a column vector by which it is post multiplied.) Thus, your model should be written: ${\rm logit}(Y=1|\bf X) = \bf X\boldsymbol\beta$.
Next, we need to be clear on what the logit is. Specifically, it is a transformation:
$$
{\rm logit}(y_i = 1) = \ln\bigg(\frac{p_i}{1-p_i}\bigg)
$$
Here $p_i$ is the probability that $y_i = 1$, the fraction within the parentheses is the odds2 that $y_i = 1$, and $\ln$ is the natural logarithm. Thus, ${\rm logit}(y_i = 1)$ is the log odds that $y_i = 1$. When the right hand side in your model is $0$, the log odds is $0$, so the probability is $.5$, not $0$.
Lastly, when you have a categorical variable with multiple (i.e., $>2$) levels, care must be taken to represent the variable appropriately. There are a number of ways such variables can be represented; the most common is called "reference level coding" (RLC; this is the default in R
). Another way is called "level means coding"3 (LMC). In R
, if you suppress the intercept when you have a multi-level factor (y ~ x + 0
), you will get level means coding by default. Let's consider a simple case where there is a factor with three levels, with 10
observations within each level, and where the observed probabilities of success are .2, .5, .8
(meaning that the logits will be: -1.386, 0, 1.386
).
With RLC4, your design matrix will be your data matrix with a column of $1$s attached on the left side to represent the intercept, which is always present, but the column for x1
will be missing:
\begin{array}{rrrr}
{\rm obs.} &{\rm (Intercept)} &x2 &x3 \\
1 &1 &0 &0 \\
\vdots &\vdots &\vdots &\vdots \\
10 &1 &0 &0 \\
11 &1 &1 &0 \\
\vdots &\vdots &\vdots &\vdots \\
20 &1 &1 &0 \\
21 &1 &0 &1 \\
\vdots &\vdots &\vdots &\vdots \\
30 &1 &0 &1
\end{array}
The result of this strange-seeming arrangement is that the (Intercept)
will represent x1
(this is the "reference level"), while x2
and x3
will represent the differences between the estimates for these levels and the reference level in your output.
If we use LMC, we won't have an intercept column, with nothing but $1$s, but you will see your missing $x1$ column, which will indicate the observations that were in the first level of the factor:
\begin{array}{rrrr}
{\rm obs.} &x1 &x2 &x3 \\
1 &1 &0 &0 \\
\vdots &\vdots &\vdots &\vdots \\
10 &1 &0 &0 \\
11 &0 &1 &0 \\
\vdots &\vdots &\vdots &\vdots \\
20 &0 &1 &0 \\
21 &0 &0 &1 \\
\vdots &\vdots &\vdots &\vdots \\
30 &0 &0 &1
\end{array}
In your output, the intercept will be missing but you will see each level represented. In this case, the estimates are the log odds of the outcome in each level directly.
Another important change to be aware of is that with RLC, the test (e.g., $p$-value) associated with the intercept is a test of whether that parameter (i.e., the log odds of 'success' in the reference level, x1
) is equal to $0$ (i.e., if the probability is $.5$), and the tests associated with the other levels (x2
and x3
here) are tests of whether they each are equal to whatever x1
is. On the other hand, with LMC all tests are whether the parameter in question is equal to $0$ (again, if the probability equals $.5$).
Here is a quick R
demo:
x = as.factor(rep(c(1,2,3), each=10))
y = c(rep(0,8), 1, 1,
rep(c(0,1), each=5),
0,0, rep(1,8) )
RLC = glm(y~x, family=binomial)
summary(RLC)
# Call:
# glm(formula = y ~ x, family = binomial)
#
# Deviance Residuals:
# Min 1Q Median 3Q Max
# -1.7941 -0.6681 0.0000 0.6681 1.7941
#
# Coefficients:
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -1.3863 0.7906 -1.754 0.0795 .
# x2 1.3863 1.0124 1.369 0.1709
# x3 2.7726 1.1180 2.480 0.0131 *
# ...
# Null deviance: 41.589 on 29 degrees of freedom
# Residual deviance: 33.879 on 27 degrees of freedom
# AIC: 39.879
LMC = glm(y~x+0, family=binomial)
summary(LMC)
# Call:
# glm(formula = y ~ x + 0, family = binomial)
#
# Deviance Residuals:
# Min 1Q Median 3Q Max
# -1.7941 -0.6681 0.0000 0.6681 1.7941
#
# Coefficients:
# Estimate Std. Error z value Pr(>|z|)
# x1 -1.386e+00 7.906e-01 -1.754 0.0795 .
# x2 -3.511e-17 6.325e-01 0.000 1.0000
# x3 1.386e+00 7.906e-01 1.754 0.0795 .
# ...
# Null deviance: 41.589 on 30 degrees of freedom
# Residual deviance: 33.879 on 27 degrees of freedom
# AIC: 39.879
Notice that the residuals, the deviances, the degrees of freedom, and the AIC are identical between the two models. Importantly, notice that the Estimate
and Pr(>|z|)
for (Intercept)
and x1
are identical in RLC
and LMC
. Further, notice that the Estimate
s for x2
and x3
in RLC
are equal to the differences in the estimates in LMC
: viz., 0--1.386 = 1.386
, and 1.386--1.386 = 2.7726
. Lastly, notice that the Pr(>|z|)
s differ for x2
and x3
in RLC
and LMC
, as they are testing different null hypotheses.
1. See, e.g., here and here.
2. For more on probabilities and odds, see my answer here.
3. There are many more, see here for some.
4. I cover some material related to this here.