Skip to main content
deleted 2 characters in body
Source Link
StatsStudent
  • 11.5k
  • 4
  • 44
  • 75

@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.

In the first part of your question, you asked about the computation of:

$$ log( odds(B=1|A) = \beta_0 + \beta_1 x_1 $$$$ 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).

@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.

In the first part of your question, you asked about the computation of:

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

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).

@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.

In the first part of your question, you asked about the computation of:

$$ 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).

Source Link
StatsStudent
  • 11.5k
  • 4
  • 44
  • 75

@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.

In the first part of your question, you asked about the computation of:

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

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).