Docsity

Logistic and Poisson Regression: A Case Study on Obesity in the United States, Lecture notes of Statistics

Partial preview of the text

Download Logistic and Poisson Regression: A Case Study on Obesity in the United States and more Lecture notes Statistics in PDF only on Docsity!

Regression Analysis

Module 4: Logistic and Poisson Regression

Outline of Lessons

1. Logistic Regression
2. Poisson Regression

3. Classification Methods and Measurements

4. Case Study1: Logistic Regression

5. Case Study 2

Nicoleta Serban

Gamze Tokol-Goldsman

Dave Goldsman

Regression Analysis

Module 4: Logistic and Poisson Regression

H. Milton Stewart School of Industrial and Systems Engineering

4.4 Case Study 1: Logistic Regression

Case Study Overview

❑ Objective :
  • Use National Health and Nutrition Examination Survey (NHANES) to create a
model used to predict likelihood of obesity.
  • Identify predicting factors with predictive power
❑ Variables :
  • Response Variable: Whether an adult is classified as obese
  • Predicting Variables: Age, Education Level, Gender

Data

Training Data (4,314 Observations)

Testing Data (1,000 Observations)

Objective :

  • Use National Health and Nutrition Examination

Survey (NHANES) to create a model used to predict

likelihood of obesity.

  • Identify predicting factors with predictive power

Variables :

  • Response Variable: Whether an adult is classified as

obese

  • Predicting Variables: Age, Education Level, Gender

Data

Training Data (4,314 Observations)

Testing Data (1,000 Observations)

Case Study Overview

Age variable

  • Present as a continuous variable

in the data

  • Recoded into classes (or ranges)

like

  • Class 1: 18-24 years
  • Class 2: 25-34 years
  • etc.

Exploratory Data Analysis

## Exploratory data analysis: Response vs Predictors

tb_obage = xtabs(~obesityind+agegr)

tb_obgender = xtabs(~obesityind+gender)

tb_obedu = xtabs(~obesityind+edu)

barplot(prop.table(tb_obage), axes=T, space=0.3, horiz=T,

xlab="Proportion of Not Obese (blue) vs Obese (Brown)",

col=c("blue","brown"), main="Obesity by Age Group")

barplot(prop.table(tb_obgender), axes=T, space=0.3, horiz=T,

xlab="Proportion of Not Obese (blue) vs Obese (Brown)",

col=c("blue","brown"), main="Obesity by Gender")

barplot(prop.table(tb_obedu), axes=T, space=0.3, horiz=T,

xlab="Proportion of Not Obese (blue) vs Obese (Brown)",

col=c("blue","brown"), main="Obesity by Education Level")

Exploratory Data Analysis

Model Estimation

## Fit a logistic regression model

model = glm(Obesity~agegr+gender+edu, family=binomial)

summary(model)

…

…

Null deviance: 5739.9 on 4313 degrees of freedom

Residual deviance: 5641.3 on 4304 degrees of freedom

…

Estimate Std. Error z value Pr(>|z|)

(Intercept) - 1.20581 0.15730 - 7.666 1.78e-14 ***

agegr25to34 0.47271 0.14428 3.276 0.001052 **

agegr35to44 0.76486 0.14196 5.388 7.13e-08 ***

agegr45to64 0.84815 0.13240 6.406 1.49e-10 ***

agegr65+ 0.60086 0.13751 4.370 1.24e-05 ***

genderFemale 0.23041 0.06363 3.621 0.000293 ***

edu9to11Grade 0.05632 0.12229 0.461 0.

eduHighSchool - 0.03440 0.11436 - 0.301 0.

eduSomeCollege 0.13947 0.11036 1.264 0.

eduCollege+ - 0.40077 0.11757 - 3.409 0.000653 ***

෡ 𝜷 𝒂𝒈𝒆𝒈𝒓𝟐𝟓𝒕𝒐𝟑𝟒

= 𝟎. 𝟒𝟕𝟐𝟕

The ratio of the odds of obesity for age

group 25-34 versus the age group 18- 24

is exp(0.4727) = 1.604 (or, equivalently

the log odds ratio is 0.4727), holding all

other predicting variables fixed. Odds of

obesity for age group 25-34 are 60.4%

higher than for age group 18- 24

(baseline group).

෡ 𝜷 𝒈𝒆𝒏𝒅𝒆𝒓𝒇𝒆𝒎𝒂𝒍𝒆

= 𝟎. 𝟐𝟑𝟎𝟒

The ratio of the odds of obesity for

females versus males is 1.259, holding

all other predicting variables fixed. Odds

of obesity for females is 26% higher than

for males.

Model Estimation

## Fit a logistic regression model

model = glm(Obesity~agegr+gender+edu, family=binomial)

summary(model)

…

…

Null deviance: 5739.9 on 4313 degrees of freedom

Residual deviance: 5641.3 on 4304 degrees of freedom

…

Estimate Std. Error z value Pr(>|z|)

(Intercept) - 1.20581 0.15730 - 7.666 1.78e-14 ***

agegr25to34 0.47271 0.14428 3.276 0.001052 **

agegr35to44 0.76486 0.14196 5.388 7.13e-08 ***

agegr45to64 0.84815 0.13240 6.406 1.49e-10 ***

agegr65+ 0.60086 0.13751 4.370 1.24e-05 ***

genderFemale 0.23041 0.06363 3.621 0.000293 ***

edu9to11Grade 0.05632 0.12229 0.461 0.

eduHighSchool - 0.03440 0.11436 - 0.301 0.

eduSomeCollege 0.13947 0.11036 1.264 0.

eduCollege+ - 0.40077 0.11757 - 3.409 0.000653 ***

## Prediction Accuracy

library(boot)

cost0.5 = function(y, pi){

ypred=rep(0,length(y))

ypred[pi>0.5] = 1

err = mean(abs(y-ypred))

return(err)}

obdata.fr = data.frame(cbind(Obesity, agegr, gender, edu))

## classification error for 10-fold cross-validation

cv.err = cv.glm(obdata.fr, model, cost=cost0.5, K=10)$delta[1]

cv.err = c(cv.err0.3, cv.err0.35, cv.err0.4, cv.err0.45, cv.err0.5,

cv.err0.55, cv.err0.6, cv.err0.65)

## Smallest prediction error is 0.

plot(c(0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65), cv.err,

type="l", lwd=3, xlab="Threshold", ylab="CV Classification Error")

Predictive Power

Prediction accuracy is highest and equal for thresholds above 0.5. Why?

  • It is the same prediction accuracy as if we were to replace all

predictions with 0 (that is, predict everyone is not obese).

  • The model has no predictive power since it performs worse than

prediction without modeling.

Predictive Power

  • Prediction accuracy is highest at 0.5; it is similar as the prediction

accuracy if we were to predict everyone is not obese.

  • The prediction accuracy using the fitted model did not improve for the

test data.

Prediction for Test Data

### Aggregate data for Logistic Regression with repetitions

obdata.agg.n = aggregate(Obesity~agegr+gender+edu, FUN=length)

obdata.agg.y = aggregate(Obesity~agegr+gender+edu, FUN=sum)

obdata.agg = data.frame(Obesity = obdata.agg.y$Obesity,

Total = obdata.agg.n$Obesity,

agegr = obdata.agg.n$agegr,

gender = obdata.agg.n$gender,

edu = obdata.agg.n$edu)

## Fit a logistic regression model

model.agg = glm(cbind(Obesity,Total-Obesity)~agegr+gender+edu,

data=obdata.agg, family=binomial)

## Test for GOF: Using deviance residuals

c(deviance(model.agg), 1-pchisq(deviance(model.agg),40))

[1] 29.0640209 0.

Logistic Regression With Replications

summary(model.agg)

Coefficients:

Null deviance: 127.701 on 49 degrees of freedom

Residual deviance: 29.064 on 40 degrees of freedom

  • Regression coefficient output

for estimation and statistical

inference is the same with or

without replications.

  • Null and residual deviance

output is different with

replications. Why?

Logistic Regression With Replications

Estimate Std. Error z value Pr(>|z|)

(Intercept) - 1.20581 0.15730 - 7.666 1.78e-14 ***

agegr25to34 0.47271 0.14428 3.276 0.001052 **

agegr35to44 0.76486 0.14196 5.388 7.13e-08 ***

agegr45to64 0.84815 0.13240 6.406 1.49e-10 ***

agegr65+ 0.60086 0.13751 4.370 1.24e-05 ***

genderFemale 0.23041 0.06363 3.621 0.000293 ***

edu9to11Grade 0.05632 0.12229 0.461 0.

eduHighSchool - 0.03440 0.11436 - 0.301 0.

eduSomeCollege 0.13947 0.11036 1.264 0.

eduCollege+ - 0.40077 0.11757 - 3.409 0.000653 ***

res = resid(model.agg, type="deviance")

par(mfrow=c(2,2))

boxplot(res~agegr,

xlab="Age Group",

ylab="Std residuals",

data=obdata.agg)

boxplot(res~gender,

xlab="Gender",

ylab="Std residuals",

data = obdata.agg)

qqnorm(res, ylab="Std residuals")

qqline(res, col="blue", lwd=2)

hist(res, 10, xlab="Std residuals", main="")

Residual Analysis