# question

Given a table such as : $$\begin{array}{ll|ll} & A & {} \\ & & 0 & 1 \\ \hline B& 1 & 44 & 27 \\ &0 & 443 & 95 \end{array}$$

If I wanted to develop a logistic regression model that included $$A$$ only, how would I go about that.

# following Maarten Buis example

Following this but predicting $$A$$ instead of $$B$$

$$\ln( \text{Odds}(A=1 \vert B)) = \beta_0 + \beta_1 B$$

Then $$\beta_0$$ is found from the log odds of $$A$$ being 1 when $$B=0$$, which is $$\ln( 95/443) = -1.54$$. So the odds of $$A$$ given $$B=0$$ are $$95/443$$.

Then for $$\beta_1$$ we have the log odds of $$A$$ when $$B=1$$ which is $$\ln( 27 / 44 ) = -0.49$$. Meaning that for a unit increase in $$B$$ the odds change by $$(27/44)\div(95/443) \approx 2.9$$. About three times larger if we predict $$A$$ from $$B$$, which matches the change in predicting $$B$$ from $$A$$.

You need to choose whether $$A$$ or $$B$$ is your dependent/explained/left-hand-side/$$y$$-variable. Let's say $$B$$ is the variable you want to explain, and $$A$$ is the variable with which you explain $$B$$. So now you can write the regression as:

$$\ln(Odds(B=1|A))= \beta_0+\beta_1A$$

So $$\beta_0$$ is a constant, so it is the log odds of $$B$$ being 1 when all $$x$$-variables (in this case just $$A$$) equal 0. The odds is the number of successes per failure, which in your example is $$\frac{44}{443}\approx0.10$$. Taking the log of that will give us $$\beta_0$$, which for your table is approximately $$-2.3$$.

$$\beta_1$$ is the log odds ratio. The odds ratio is, as the name suggest, a ratio of odds. It answers the question, by what factor does the odds change for a unit increase in $$x$$. The odds was $$\frac{44}{443}$$ when $$A$$ was 0, and the odds is $$\frac{27}{95}$$ when $$A$$ is 1, so odds changes by a factor $$\frac{\frac{27}{95}}{\frac{44}{443}} = \frac{27\times443}{95\times44}\approx2.9$$. So the odds of $$B=1$$ is almost three times larger for the group $$A=1$$ compared to the group $$A=0$$. Taking the log of the odds ratio will give is $$\beta_1$$, in this case approximately $$1.1$$

These manual computation were possible because this is a so called saturated model; the model will exactly reproduce the cell counts. If, for example, we added a second explanatory variable but not the interaction, then this would no longer be a saturated model, and we would have to use an iterative algorithm to find the maximum likelihood estimates of the parameters.

In your question you referred to just using $$A$$, and shown the marginal distribution of $$A$$. That would be equivalent to a logistic regression with only a constant and no explanatory variables. This too is a saturated model, and the constant in that model is the log of the odds you estimated.

Edit, response to edit in original question

What you found is correct: the odds ratio is symmetric. This property is for example used in case control studies.

• Thanks, that was very helpful. Could you please see the edit that I've made to see whether I'm understanding you correctly. It seems that the odds ratio is the same whether I predict A from B or B from A, which doesn't seem right.
– baxx
Commented Jan 15, 2019 at 15:38

@Maarten Buis has done an excellent job explaining your logistic regression questions, but I figured I'd supplement his answer with some sample R code so you can see the calculations performed in a statistical analysis program.

$$log( odds(B=1|A) = \beta_0 + \beta_1 A$$

We can get this model ( log-odds of $$B=1$$ given $$A$$) as follows:

> A<-c(rep(0,44+443), rep(1, 27+95))
> B<-c(rep(1, 44), rep(0, 443), rep(1, 27), rep(0, 95))
>
> #view dummy table in table form
> table(B,A)
A
B     0   1
0 443  95
1  44  27
>
> #run log(odds(B=1|A))
> mylogit_BgivenA <- glm(B ~ A, family = "binomial")
> mylogit_BgivenA

Call:  glm(formula = B ~ A, family = "binomial")

Coefficients:
(Intercept)            A
-2.309        1.051


You can see from the coefficients the -2.309 here, corresponds to the log odds of B being equal to 1 given, all the values of A are equal to 0. This also corresponds to Maarten's approximate value of -2.3.

Moving on to your second question, we can find the probabilities and log odds of A by regressing A onto a constant value of 1:

> mylogit_Aonly <- glm(A ~1, family = "binomial")
>
> mylogit_Aonly

Call:  glm(formula = A ~ 1, family = "binomial")

Coefficients:
(Intercept)
-1.384

>
> exp_b0<-exp(-1.384)
> #probability of event A given no explanatory variables
> #calculate the probability of p_A
> exp_b0/(1+exp_b0)

[1] 0.2003674


Lastly, note that $$log(odds(B=1|A)) \ne log(odds(A=1|B))$$. You can verify this by running another logistic regression and comparing the results with the first output above:

> #run log(odds(A=1|B))
> mylogit_AgivenB <- glm(A ~ B, family = "binomial")
> mylogit_AgivenB

Call:  glm(formula = A ~ B, family = "binomial")

Coefficients:
(Intercept)            B
-1.540        1.051


Note that the value of the intercept (-1.54) is different than that calculated in the first output shown (-2.309).