Docsity

7. Logistic Regression 2020, Exercises of Design

Toggle sidebar
bg1
BIOSTATS 640 - Spring 2020 7. Logistic Regression – Stata Users Page 1 of 66
Nature
Population/
Sample
Observation/
Data
Relationships/
Modeling
Unit 7
Logistic Regression
“To all the ladies present and some of those absent”
- Jerzy Neyman
What behaviors influence the chances of developing a sexually transmitted
disease? Comparing demographics, health education, access to health care,
which of these variables are significantly associated with failure to obtain an HIV
test? Among the several indicators of risk, including age, co-morbidities, severity
of disease, which are significantly associated with surgical mortality among
patients undergoing transplant surgery? In all of these examples, the outcome
observed for each individual can take on only one of two possible values:
positive or negative test, alive or dead, remission or non-remission, and so on.
Collectively, the data to be analyzed are proportions.
Proportions have some important features that distinguish them from data
measured on a continuum. Proportions (1) are bounded from below by the value
of zero (or zero percent) and bounded from above by one (or 100 percent); (2) as
the proportion gets close to either boundary, the variance of the proportion gets
smaller and smaller; thus, we cannot assume a constant variance; and (3)
proportions are not distributed normal. Normal theory regression models are
not appropriate for the analysis of proportions.
In unit 4, Categorical Data Analysis, emphasis was placed on contingency table
approaches for the analysis of such data and it was highlighted that these methods
should always be performed for at least two reasons: (1) they give a good feel for
the data; and (2) they are free of the assumptions required for regression
modeling.
Unit 7 is an introduction to logistic regression approaches for the analysis of
proportions where it is of interest to explore the roles of possibly several
influences on the observed proportions.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42

Partial preview of the text

Download 7. Logistic Regression 2020 and more Exercises Design in PDF only on Docsity!

Nature Population/ Observation/ Relationships/ Analysis/

Unit 7

Logistic Regression

“To all the ladies present and some of those absent”

- Jerzy Neyman

What behaviors influence the chances of developing a sexually transmitted

disease? Comparing demographics, health education, access to health care,

which of these variables are significantly associated with failure to obtain an HIV

test? Among the several indicators of risk, including age, co-morbidities, severity

of disease, which are significantly associated with surgical mortality among

patients undergoing transplant surgery? In all of these examples, the outcome

observed for each individual can take on only one of two possible values:

positive or negative test, alive or dead, remission or non-remission, and so on.

Collectively, the data to be analyzed are proportions.

Proportions have some important features that distinguish them from data

measured on a continuum. Proportions (1) are bounded from below by the value

of zero (or zero percent) and bounded from above by one (or 100 percent); (2) as

the proportion gets close to either boundary, the variance of the proportion gets

smaller and smaller; thus, we cannot assume a constant variance ; and (3)

proportions are not distributed normal. Normal theory regression models are

not appropriate for the analysis of proportions.

In unit 4, Categorical Data Analysis, emphasis was placed on contingency table

approaches for the analysis of such data and it was highlighted that these methods

should always be performed for at least two reasons: (1) they give a good feel for

the data; and (2) they are free of the assumptions required for regression

modeling.

Unit 7 is an introduction to logistic regression approaches for the analysis of

proportions where it is of interest to explore the roles of possibly several

influences on the observed proportions.

Nature Population/ Observation/ Relationships/ Analysis/

Table of Contents

Topic

Learning Objectives …………………………….…………………………….

  1. From Linear Regression to Logistic Regression …................................…..

  2. Use of VDT’s and Spontaneous Abortion …..............................................

  3. Definition of the Logistic Regression Model .…................................…….

  4. Estimating Odds Ratios …………………................................……………

  5. Estimating Probabilities …………….........................……………..………

  6. The Deviance Statistic …………….........................……….……………..

a. The Likelihood Ratio Test …….........................……………………….

b. Model Development …………................................………………….

  1. Illustration – Depression Among Free-Living Adults ………..………

  2. Regression Diagnostics ……………...........................………....…………

a. Assessment of Linearity ………………………………….……………

b. Hosmer-Lemeshow Goodness of Fit Test ……..................................….

c. The Linktest ………………………………………………..………….

d. The Classification Table ………………..................................………..

e. The ROC Curve ……………………….................................………….

f. Pregibon Delta Beta Statistic ………….................................…………

  1. Example - Disabling Knee Injuries in the US Army ...................................

Appendix

Overview of Maximum Likelihood Estimation ………..............................… 62

Nature Population/ Observation/ Relationships/ Analysis/

1. From Linear Regression To Logistic Regression

An Organizational Framework

In unit 5 ( Regression and Correlation ), we considered single and multiple predictor regression models for a

single outcome random variable Y assumed continuous and distributed normal.

In unit 7 ( Logistic regression ), we consider single and multiple regression models for a single outcome

random variable Y assumed discrete, binary, and distributed bernoulli.

Unit 5

Normal Theory Regression

Unit 7

Logistic Regression

Y

  • univariate
  • continuous
  • Example: Y = cholesterol
    • univariate
    • discrete, binary
    • Example: Y = dead/alive

X

1

, X

2

, ….., X

p

  • one or multiple
  • discrete or continuous
  • treated as fixed
    • one or multiple
    • discrete or continuous
    • treated as fixed

Y | X

1

=x

1

, .., X

p

=x

p

  • Normal (Gaussian) - Bernoulli (or binomial)

E(Y| X

1

=x

1

X

p

=x

p

Right hand side of

model

Link

Estimation

Least squares (= maximum

likelihood)

Maximum Likelihood

Tool

Residual sum of squares Deviance statistic

Tool

Partial F Test Likelihood Ratio Test

1 p

Y|X ...X 0 1 1 p p

μ =β +β x +...+β x

1 p 1 p

Y|X ...X Y|X ...X

0 1 1 p p

1+exp - β +β x +...+β x

é ù

ë û

0 1 1 p p

β +β x +...+β x

0 1 1 p p

β +β x +...+β x

"natural" or "identity"

Y|X

1

...X

p

0

1

x

1

p

x

p

1 p

1 p

1 p 1 p

Y|X ...X

Y|X ...X

Y|X ...X Y|X ...X

0 1 1 p p

"logit"

logit[μ ]

logit[π ]

=ln π 1 π

= β +β x +...+β x

é ù

ë û

Nature Population/ Observation/ Relationships/ Analysis/

2. Use of Video Display Terminals and Spontaneous Abortion

Consider the following published example of logistic regression.

Source: Schnorr et al (1991) Video Display Terminals and the Risk of Spontaneous Abortion. New England

Journal of Medicine 324 : 727-33.

Background:

Adverse pregnancy outcomes were correlated with use of video display terminals (VDT’s) beginning in 1980.

Subsequent studies were inconsistent in their findings.

Previous exposure assessments were self-report or derived from job title descriptions.

Electromagnetic fields were not previously measured.

Research Question:

What is the nature and significance of the association, as measured by the odds ratio, between exposure to

electromagnetic fields emitted by VDTs and occurrence of spontaneous abortion, after controlling for

  • History of prior spontaneous abortion
  • Cigarette Smoking
  • History of thyroid condition

Design: Retrospective cohort investigation of two groups of full-time female telephone operators.

882 Pregnancies: N

Spontaneous Abortion

n %

Exposed 366 54 14.8%

Unexposed 516 82 15.9%

Nature Population/ Observation/ Relationships/ Analysis/

3. Definition of the Logistic Regression Model

We suspect that multiple factors, especially use of video display terminals, contribute to an individual’s odds

of spontaneous abortion.

The outcome or dependent variable is Y=sab. Its value is y and

= 1 if spontaneous abortion occurred

0 otherwise

The predictors that might influence the odds of SAB are several:

X

1

= avgvdt

X

2

= numcigs

X 3 = priorsab

X

4

= smokstat

X

5

= prthyr, and

X

6

= vdtexpos

We are especially interested in

X

6

= vdtexpos (coded = 1 for exposed and = 0 for NON exposed) and

X

1

= avgvdt

Among the N=882 in our sample, we have potentially N=882 unique probabilities of spontaneous abortion.

p 1

, p 2

, …, p N

For the i

th

person

p i

= Function ( X 1i

, X

2i

, X

3i

, X

4i

, X

5i

, X

6i

Pr [ Y i

= 1] = p i

Pr [ Y i

= 0] = (1 - p i

Nature Population/ Observation/ Relationships/ Analysis/

How do we model the N=882 individual probabilities p

i

in relationship to the predictors?

Recall. Each profile of values, X = [ X 1

=x 1

X 2

=x 2

, …. X 6

=x 6

], defines a sub-population with their own distribution of outcomes Y. For example

the women with X 3

=1 are the women with a history of prior spontaneous abortion, and are distinct from the women with X 3

=0 (who have no such

prior history). And so on; we can talk about distinct sub-populations based on the entire profile of values on X 1

, X 2

, … X 6

.

Review of normal theory linear regression analysis:

Y |[X

1

, X

2

, X

3

, X

4

, X

5

, X

6

] (read: “Y given [X 1

, X

2

, X

3

, X

4

, X

5

, X

6

]” is assumed to be distributed

normal (Gaussian)

with mean = μ Y|x

and variance=.

The mean of Y at [X 1

, X

2

, X

3

, X

4

, X

5

, X

6

] is modeled linearly in x = [X 1

, X

2

, X

3

, X

4

, X

5

, X

6

]

Thus mean of Y | [X 1

, X

2

, X

3

, X

4

, X

5

, X

6

] = E [Y | (X

1

, X

2

, X

3

, X

4

, X

5

, X

6

) ] = μ Y|x

In normal theory linear regression:

E[Y| x ] = μ

x

= b

0

+ b

1

X

1

+ b

2

X

2

+ b

3

X

3

+ b

4

X

4

+ b

5

X

5

+ b

6

X

6

“natural link” “right hand side is linear in the predictors”

In a logistic model regression analysis, the framework is a little different:

Y is assumed to be distributed Bernoulli

with mean=p x

and variance= p x

(1-p x

We do not model the mean of Y|X=x = p

x

linearly in x = [X 1

…

X

6

].

Instead, we model the logit of the mean of Y|X=x = p

x

linearly in x = [X 1

…

X

6

].

Logit [ E(Y|X) ] = logit[ p

x

] = = b

0

+ b

1

X

1

+ b

2

X

2

+ b

3

X

3

+ ...+ b

5

X

5

+ b

6

X

6

“logit link” “right hand side is linear in the predictors”

2

Y X |

s

ln

π

x

1 − π

x

Nature Population/ Observation/ Relationships/ Analysis/

Assumptions:

  1. Each Y i

follows a distribution that is Bernoulli with parameter E[Y | X ] =.

  1. The Y 1

, Y

2

…

, Y

N

are independent.

  1. The values of the predictors, X i

=x i

…

X

i

=x i

, are treated as fixed.

  1. The model is correct (this is also referred to as “linearity in the logit”).

logit[ E(Y)| X 1

=x 1

, X

2

=x 2

, …, X

6

=x 6

]

= logit [ p x

]

= b 0

  • b 1

X

1

  • b 2

X

2

  • b 3

X

3

  • b 4

X

4

  • b 5

X

5

  • b 6

X

6

  1. No multicollinearity

  2. No outliers

  3. Independence

p

x i

Nature Population/ Observation/ Relationships/ Analysis/

3. Estimating Odds Ratios

For now, assume that we have a fitted model. We’ll get to the details of estimation later.

Once a logistic regression model has been fit, the prediction equation can be used to estimate odds ratio (OR)

measures of association.

Example 1 : What is the estimated crude relative odds (OR) of spontaneous abortion (SAB) associated with

any exposure (1 = exposed, 0 = not exposed) to a video display terminal (VDTEXPOS)?

Step 1:

To obtain crude odds ratios, either a 2x2 table can be used or a one predictor logistic regression model can be

fit. Here, it is given by

logit { probability [SAB=1] } =

b

0

b

1

VDTEXPOS

Stata

. * The following assumes you have downloaded and opened vdt.dta. . logit sab vdtexpos

Logistic regression Number of obs = 882

LR chi2(1) = 0.

= Likelihood Ratio Statistic

for current model (“full”) v

intercept only model (“reduced”)

Analogous to Overall F

Prob > chi2 = 0. 6443

Log likelihood = - 379.08045 Pseudo R2 = 0.0 003

(-2) ln L = 758.

Wald Z Wald Z p-value (2 sided) using Normal(0,1)


depressed | Coef. Std. Err. z P>|z| [95% Conf. Interval]

-------------+----------------------------------------------------------------

vtexpos | - .0876939. 1903232 - 0. 46 0.645 -. 4607204. 2853327

_cons | - 1.666325. 1204129 - 13. 84 0.0 00 - 1. 90233 - 1. 43032


z = Wald Z = [ Coef ] / [ Std. Err. ]

= [ beta – 0 ] / [ SE(beta) ] ~ Normal(0,1) when ß 1

= 0

Yielding the following prediction equation

Fitted logit { pr[sab=1] } = - 1.66633 - 0.08769*vdtexpos

=

ˆ

β

1

=

ˆ

β

0

Nature Population/ Observation/ Relationships/ Analysis/

Stata Illustration – Obtaining estimated odds ratios after logistic regression

Method 1. Command logit with option or

. logit sab vdtexpos, or

Method 2. Command logistic

. logistic sab vdtexpos

Nature Population/ Observation/ Relationships/ Analysis/

The two profiles being compared can differ on several predictors! Let’s try another one.

Here is the wonderful algebra, in all its glory:

For two profiles of predictor variable values, “comparison” versus “reference”

OR

comparison versus reference

= exp { logit (π

comparison

) – logit (π

reference

ln { OR

comparison versus reference

} = logit (π

comparison

) – logit (π

reference

Example 2 - What is the estimated relative odds (OR) of spontaneous abortion (SAB) for a person who is not

exposed to a VDT, smokes 10 cigarettes per day, has no history of prior SAB, and no thyroid condition

relative to a person who has an average of 20 hours exposure to a VDT, is a nonsmoker, has a history of prior

SAB and does have a thyroid condition?

Step 1:

Here the model fit is the 4 predictor model:

logit { probability [sab=1] }

= b 0

  • b 1

avgvdt + b 2

numcigs + b 3

priorsab + b 4

prthyr

Estimation now yields (output not shown).

fitted logit { prob[sab=1] }

= - 1.95958 + 0.00508(avgvdt) + 0.04267(numcigs) + 0.38500(priorsab)

  • 1.27420(prthyr)

Step 2:

Calculate the two predicted logits and compute their difference.

Value of Predictor for Person

“comparison” “reference”

avgvdt 0 20

numcigs 10 0

priorsab 0 1

prthyr 0 1

Nature Population/ Observation/ Relationships/ Analysis/

In General:

The Odds Ratio estimate ( ) of association with outcome

accompanying a unit change in the predictor X is a

function of the estimated regression parameter

= exp { }

Tip – OR 10 unit change in X

= exp [ 10β ]*

A hypothesis test of null: OR=

Is equivalent to

A hypothesis test of null:

b

For a rare outcome (typically disease), the relative risk ( ) estimate of

association with outcome accompanying a unit change in

the predictor X is reasonably estimated as a function of the

estimated regression parameter b

= exp { }, approximately

ˆ

OR

ˆ

β

UNIT change in X

ˆ

OR

ˆ

β

ˆ

RR

UNIT change in X

ˆ

RR

ˆ

β

Nature Population/ Observation/ Relationships/ Analysis/

5. Estimating Probabilities

Again, let’s assume that we have a fitted model. We’ll get to the details of estimation later.

Once a logistic regression model has been fit, the prediction equation can also be used to estimate probabilities

of event occurrence. The prediction equation can be used to estimate probabilities of event of disease if the

study design is a cohort; it is used to estimate probabilities of history of exposure if the study design is case-

control.

Reminder …– it is not possible to estimate probability of disease from analyses of case-control studies.

Recall that for Y distributed Bernoulli

E [ Y ] = π = Probability of event occurrence

Example 1 - Under the assumption of a cohort study design, what is estimated probability of spontaneous

abortion (sab) for a person with any exposure to a video display terminal? Consider the single predictor

model containing the predictor vdtexpos)

Step 1:

Recall that we obtained the following equation for the fitted logit for the one predictor model containing

VDTEXPOS:

Predicted logit { prob[SAB=1| vdtexpos] }

= - 1.66633 - 0.08769*VDTEXPOS

Step 2:

Utilizing the algebra on page 9 , we have:

Step 3:

Set VDTEXPOS=1, b 0

= - 1.66633, b 1

=-0.08769 and solve

0 1

= β + β [vdtexpos]

0 1 0 1

VDTEXPOS=

0 1 0 1

exp β +β [vdtexpos] exp β +β

Estimated pr[SAB=1] = ˆ

1+exp β +β [vdtexpos] 1+exp β +β

p = =

exp -1.66633 - 0.08769[1]

Estimated pr[SAB=1]=

1+exp -1.66633 - 0.08769[1]

= =

Nature Population/ Observation/ Relationships/ Analysis/

Deviance Statistic, D = - 2

= (-2) ln (L

current

) - (-2) ln (L

saturated

Deviance df = [Sample size] – [# fitted parameters]

where

L

current

= likelihood of data using current model

Lsaturated = likelihood of data using the saturated model

Notes -

(1) By itself, the deviance statistic does not have a well defined distribution

(2) However, differences of deviance statistics that compare hierarchical models do have well defined

distributions, namely chi square distributions.

A Feel for the Deviance Statistic

(1) Roughly, the deviance statistic D is a measure of what remains unexplained.

Hint – The analogue in normal theory regression is the residual sum of squares (SSQ error)

(2) A deviance statistic value close to zero says that a lot is explained and, importantly,

that little remains unexplained. à The current model with its few predictors performs

similarly to the saturated model that permits a separate predictor for each person.

(3) WARNING! The deviance statistic D is NOT a measure of goodness-of-fit. Recall

that we said the same thing about the overall F-statistic in normal theory regression.

(4) The deviance statistic D is the basis of the likelihood ratio test.

(5) The likelihood ratio test is used for the comparison of hierarchical models.

Recall – In normal theory regression, hierarchical models are compared using the Partial F-test.

ln

L

current

L

saturated

Nature Population/ Observation/ Relationships/ Analysis/

a. The Likelihood Ratio (LR) Test

Likelihood Ratio (LR) Test

Under the assumptions of a logistic regression model and the comparison of the hierarchical

models:

For testing:

A Likelihood Ratio Test Statistic LR, defined

LR = Deviance

REDUCED

- Deviance FULL

= [ (-2) ln (L)

REDUCED

- (-2) ln(L) SATURATED

] - [ (-2) ln (L)

FULL

- (-2) ln(L) SATURATED

]

= [ (-2) ln (L)

REDUCED

] - [ (-2) ln (L)

FULL

]

has null hypothesis distribution that is Chi Square

DF=k

Thus, rejection of the null hypothesis occurs for

Test statistic values, LR = large

and accompanying p-value= small

Tip – In practice, we obtain LR using the 2

nd

formula; it says: LR = [ (-2) ln (L) REDUCED

] - [ (-2) ln (L) FULL

]

1 2 p 0

p+1 p+2 p+k p+1 p+1 p+k p+

1 1 p p

1 2 p 0 1 1 p p k

Reduced: logit[π | X ,X ...,X ] = β +β X +...+β X

Full: logit[π | X ,X ...,X , X ,X ,...,X ] = β +β X +...+β X +β X +...+β X

O p+1 p+2 p+k

A

H : β = β = ... = β = 0

H : not