1
$\begingroup$

I have a GLM looking at death rate of characters based on gender:

fit2 <- glm(Death~as.factor(Gender), data=data, family=binomial(link="logit"))

This is my output: enter image description here

Gender is a binary variable where 1 means the character is female, and 0 means they're male. My intercept is -.33 and my coefficient as.factor(Gender)1 is -.23. Does this mean that the intercept is looking at males and the coefficient is looking at females? I'm very confused on how to interpret this. Also, if I add other predictor variables, for example age, will that change the meaning of the intercept?

$\endgroup$
1
  • 1
    $\begingroup$ If one of the answers below solves your problem, you're encourage to click on the check-mark to accept it ... $\endgroup$
    – Ben Bolker
    Commented Dec 26, 2018 at 19:22

2 Answers 2

4
$\begingroup$

You are not explicit about your Death variable, so I am going to assume that Death = 1 if the character died and Death = 0 if the character didn't die.

Your glm model would then be a binary logistic regression model of the form:

log(odds of death) = beta0 + beta1*Gender

where Gender = 1 if the character is female and Gender = 0 if the character is male.

You can plug-in the values of 0 and 1, respectively, for Gender in the above model to get the following.

Males (for whom Gender = 0)

log(odds of death) = beta0           (1)

Females (for whom Gender = 1)

log(odds of death) = beta0 + beta1   (2)

From this, you can see that beta0 refers to the log odds of death for males, while beta0 + beta1 refers to the log odds of death for females. This means that:

beta1 = (beta0 + beta1) - beta0 

represents the difference in the log odds of death between females and males.

Now, if you exponentiate both sides of equations (1) and (2), you will get the following:

Males (for whom Gender = 0)

odds of death = exp(beta0)           (3)

Females (for whom Gender = 1)

odds of death = exp(beta0 + beta1)   (4)

Dividing (4) by (3), this means that:

(odds of death for females)/(odds of death for males) = exp(beta0 + beta1)/exp(beta0) = exp(beta1) 

In other words, exp(beta0) represents the odds of death for males, exp(beta0 + beta1) represents the odds of death for females and exp(beta1) represents the odds ratio of death for females relative to males.

Note that your computer output returns the estimated values of beta0 (-0.3334916) and beta1 (-0.2329039) under the Estimate column.

Since probability = odds/(1 + odds), you can use equations (3) and (4) to derive the probability of death for male and female characters, respectively.

Males (for whom Gender = 0)

probability of death = exp(beta0)/(1 + exp(beta0))                    (5)

Females (for whom Gender = 1)

probability of death = exp(beta0 + beta1)/(1 + exp(beta0 + beta1))     (6)

Now, let's say you add another variable called Age in your model, where Age is the age of the character at the time of death. Let's also say that Age was centered around its sample mean prior to being included in the model: Age.cen = Age - mean(Age). Your binary logistic regression model would then be:

log(odds of death) = beta0 + beta1*Gender + beta2*Age.cen

For this extended model, beta0 represents the log odds of death for a male of average age (i.e., for a subject for whom Gender = 0 and Age.Cen = 0 or, equivalently, for a male subject for whom Age = mean(Age)). Equivalently, exp(beta0) represents the odds of death for such a male. On the other hand, beta1 represents the difference in the log odds of death between females and males of the same age, while exp(beta1) represents the ratio of odds of death for females to odds of death for males of the same age.

$\endgroup$
2
$\begingroup$

Yes. R uses treatment contrasts for categorical (factor) variables by default, which means that in this case the answer is the same as if used your numeric dummy variables in the first place. (In the model matrix $X$ R includes an intercept column [all ones], followed by one or more dummy variables for each level of the categorical variable after the first; in this case the dummy variable for Gender="female" the same as your original 0/1 variable.)

If you look at the equation for the linear predictor ($\eta = \beta_0 + \beta_1 x_1$, where $\beta_0$ is the intercept and $x_1$ is your gender variable), you'll see that the value of $\eta$ (i.e., predicted log-odds of death) is $\beta_0$ for male ($x_1=0$) individuals, i.e. the probability is $g^{-1}(-0.33)$ = 0.42 (this is the plogis() function in R). For female ($x_1=1$) the predicted log-odds is $\beta_0+\beta_1 \cdot 1 = -0.56$.

If you add a numerical predictor for age your equation would be $\beta_0 + \beta_1 I(\textrm{Gender}=\textrm{female}) + \beta_2 \cdot \textrm{age}$, so the intercept would now represent the log-odds of death for a male of age zero. (Since that value might be hard to interpret, it's often recommended that you center your age variable so that the predictor variable is zero when the age is equal to the mean age; this makes the intercept the log-odds of death for a male of average age ...)

$\endgroup$
1
  • 1
    $\begingroup$ Great answer, Ben! Clear and concise - I rambled on much more in my own answer. 😀 $\endgroup$ Commented Dec 20, 2018 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.