The R program for the chapter.
In this chapter we will only be using the depression data set so we choose to use the attach function.
attach(depress)
We have skipped page 283 for now.
Table 12.1, p. 285.
Classification of individuals by depression level and sex.
table1 <- table(sex, cases)
print(table1)
0 1
1 101 10
2 143 40
Regressing depression level on sex, p. 286.
Note: We are using sex01 which is a (0, 1) variable rather than sex which is a (1, 2) variable.
depress$sex01 <- depress$sex - 1
logit1 <- glm(cases ~ sex01, depress, family=binomial)
summary(logit1)
Coefficients:
Value Std. Error t value
(Intercept) -2.312511 0.3304732 -6.997576
sex01 1.038546 0.3757731 2.763759
Regressing depression levels on age, sex and income, middle p. 287.
logit2 <- glm(cases ~ age+income+sex, depress, family=binomial)
summary(logit2)
Coefficients:
Value Std. Error t value
(Intercept) -1.60583693 0.842754515 -1.905462
age -0.02095667 0.009023527 -2.322447
income -0.03655542 0.013971982 -2.616337
sex 0.92934726 0.383808600 2.421382
Regressing depression levels on age and income, p. 287.
logit3 <- glm(cases ~ age+income, depress, family=binomial)
summary(logit3)
Coefficients:
Value Std. Error t value
(Intercept) 0.02790447 0.486489875 0.05735879
age -0.02016672 0.008888887 -2.26875686
income -0.04134262 0.013963952 -2.96066780
We have skipped pages 288-307 for now.
Regressing depression levels on age, income and sex, bottom p. 297.
logit2 <- glm(cases ~ age+income+sex, depress, family=binomial)
summary(logit2)
Coefficients:
Value Std. Error t value
(Intercept) -1.60583693 0.842754515 -1.905462
age -0.02095667 0.009023527 -2.322447
income -0.03655542 0.013971982 -2.616337
sex 0.92934726 0.383808600 2.421382
Unless you plan to work further with the depression data set it will be a good idea to detach it.
detach(depress)
