Logistic Regression. Example: Survival of Titanic passengers  We want to know if the probability of survival is higher among children  Outcome (y) =

Slides:



Advertisements
Similar presentations
Continued Psy 524 Ainsworth
Advertisements

© Department of Statistics 2012 STATS 330 Lecture 32: Slide 1 Stats 330: Lecture 32.
Irwin/McGraw-Hill © Andrew F. Siegel, 1997 and l Chapter 12 l Multiple Regression: Predicting One Factor from Several Others.
Inference for Regression
Logistic Regression Example: Horseshoe Crab Data
Logistic Regression.
Some Terms Y =  o +  1 X Regression of Y on X Regress Y on X X called independent variable or predictor variable or covariate or factor Which factors.
Chapter 13 Multiple Regression
Logistic Regression Predicting Dichotomous Data. Predicting a Dichotomy Response variable has only two states: male/female, present/absent, yes/no, etc.
Count Data Harry R. Erwin, PhD School of Computing and Technology University of Sunderland.
Chapter 12 Multiple Regression
Nemours Biomedical Research Statistics April 2, 2009 Tim Bunnell, Ph.D. & Jobayer Hossain, Ph.D. Nemours Bioinformatics Core Facility.
Basic Business Statistics, 11e © 2009 Prentice-Hall, Inc. Chap 14-1 Chapter 14 Introduction to Multiple Regression Basic Business Statistics 11 th Edition.
Nemours Biomedical Research Statistics April 23, 2009 Tim Bunnell, Ph.D. & Jobayer Hossain, Ph.D. Nemours Bioinformatics Core Facility.
Introduction to Logistic Regression Analysis Dr Tuan V. Nguyen Garvan Institute of Medical Research Sydney, Australia.
An Introduction to Logistic Regression
Ch. 14: The Multiple Regression Model building
C82MCP Diploma Statistics School of Psychology University of Nottingham 1 Linear Regression and Linear Prediction Predicting the score on one variable.
Generalized Linear Models
Logistic Regression with “Grouped” Data Lobster Survival by Size in a Tethering Experiment Source: E.B. Wilkinson, J.H. Grabowski, G.D. Sherwood, P.O.
Statistics for Managers Using Microsoft Excel, 4e © 2004 Prentice-Hall, Inc. Chap 13-1 Chapter 13 Introduction to Multiple Regression Statistics for Managers.
Logistic Regression and Generalized Linear Models:
Chapter 13: Inference in Regression
© Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28.
Lecture 15: Logistic Regression: Inference and link functions BMTRY 701 Biostatistical Methods II.
Lecture 6 Generalized Linear Models Olivier MISSA, Advanced Research Skills.
7.1 - Motivation Motivation Correlation / Simple Linear Regression Correlation / Simple Linear Regression Extensions of Simple.
© Department of Statistics 2012 STATS 330 Lecture 26: Slide 1 Stats 330: Lecture 26.
© Department of Statistics 2012 STATS 330 Lecture 25: Slide 1 Stats 330: Lecture 25.
Chapter 3: Generalized Linear Models 3.1 The Generalization 3.2 Logistic Regression Revisited 3.3 Poisson Regression 1.
Logistic Regression Pre-Challenger Relation Between Temperature and Field-Joint O-Ring Failure Dalal, Fowlkes, and Hoadley (1989). “Risk Analysis of the.
Introduction to Generalized Linear Models Prepared by Louise Francis Francis Analytics and Actuarial Data Mining, Inc. October 3, 2004.
Chapter 14 Introduction to Multiple Regression
Repeated Measures  The term repeated measures refers to data sets with multiple measurements of a response variable on the same experimental unit or subject.
Session 10. Applied Regression -- Prof. Juran2 Outline Binary Logistic Regression Why? –Theoretical and practical difficulties in using regular (continuous)
Logistic regression. Analysis of proportion data We know how many times an event occurred, and how many times did not occur. We want to know if these.
University of Warwick, Department of Sociology, 2014/15 SO 201: SSAASS (Surveys and Statistics) (Richard Lampard) Week 7 Logistic Regression I.
November 5, 2008 Logistic and Poisson Regression: Modeling Binary and Count Data LISA Short Course Series Mark Seiss, Dept. of Statistics.
Chap 14-1 Copyright ©2012 Pearson Education, Inc. publishing as Prentice Hall Chap 14-1 Chapter 14 Introduction to Multiple Regression Basic Business Statistics.
Week 5: Logistic regression analysis Overview Questions from last week What is logistic regression analysis? The mathematical model Interpreting the β.
© Department of Statistics 2012 STATS 330 Lecture 31: Slide 1 Stats 330: Lecture 31.
Lecture 4 Introduction to Multiple Regression
A preliminary exploration into the Binomial Logistic Regression Models in R and their potential application Andrew Trant PPS Arctic - Labrador Highlands.
Logistic Regression. Linear Regression Purchases vs. Income.
Applied Statistics Week 4 Exercise 3 Tick bites and suspicion of Borrelia Mihaela Frincu
© Department of Statistics 2012 STATS 330 Lecture 30: Slide 1 Stats 330: Lecture 30.
Count Data. HT Cleopatra VII & Marcus Antony C c Aa.
June 30, 2008Stat Lecture 16 - Regression1 Inference for relationships between variables Statistics Lecture 16.
Copyright ©2011 Pearson Education, Inc. publishing as Prentice Hall 14-1 Chapter 14 Introduction to Multiple Regression Statistics for Managers using Microsoft.
Business Statistics: A Decision-Making Approach, 6e © 2005 Prentice- Hall, Inc. Chap 14-1 Business Statistics: A Decision-Making Approach 6 th Edition.
© Department of Statistics 2012 STATS 330 Lecture 22: Slide 1 Stats 330: Lecture 22.
Basic Business Statistics, 10e © 2006 Prentice-Hall, Inc.. Chap 14-1 Chapter 14 Introduction to Multiple Regression Basic Business Statistics 10 th Edition.
Statistics 2: generalized linear models. General linear model: Y ~ a + b 1 * x 1 + … + b n * x n + ε There are many cases when general linear models are.
© Department of Statistics 2012 STATS 330 Lecture 24: Slide 1 Stats 330: Lecture 24.
Introduction to Multiple Regression Lecture 11. The Multiple Regression Model Idea: Examine the linear relationship between 1 dependent (Y) & 2 or more.
Statistics for Managers Using Microsoft Excel, 5e © 2008 Prentice-Hall, Inc.Chap 14-1 Statistics for Managers Using Microsoft® Excel 5th Edition Chapter.
Logistic Regression and Odds Ratios Psych DeShon.
Logistic Regression. What is the purpose of Regression?
R Programming/ Binomial Models Shinichiro Suna. Binomial Models In binomial model, we have one outcome which is binary and a set of explanatory variables.
LOGISTIC REGRESSION. Purpose  Logistical regression is regularly used when there are only two categories of the dependent variable and there is a mixture.
Logistic Regression Jeff Witmer 30 March Categorical Response Variables Examples: Whether or not a person smokes Success of a medical treatment.
Lecture 21: poisson regression log-linear regression BMTRY 701 Biostatistical Methods II.
Transforming the data Modified from:
Chapter 14 Introduction to Multiple Regression
Logistic regression.
A priori violations In the following cases, your data violates the normality and homoskedasticity assumption on a priori grounds: (1) count data  Poisson.
CHAPTER 7 Linear Correlation & Regression Methods
Basic Estimation Techniques
Multiple Regression Analysis and Model Building
Logistic Regression with “Grouped” Data
Presentation transcript:

Logistic Regression

Example: Survival of Titanic passengers  We want to know if the probability of survival is higher among children  Outcome (y) = survived/not  Explanatory (x) = age at death > titan<- read.table("D:/RShortcourse/titanic.txt",sep=",",header=T, na=".") > titan2<-na.omit(titan) > log1<- glm(titan2$Survived~titan2$Age,family=binomial("logit")) Since “logit” is the default, you can actually use: > log1<-glm(titan2$Survived~titan2$Age,binomial) > summary(log1)

Example in R Call: glm(formula = titan$Survived ~ titan$Age, family = binomial("logit")) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) titan$Age Signif. codes: 0 ‘***’ ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: on 755 degrees of freedom Residual deviance: on 754 degrees of freedom AIC:

Plot > plot(titan2$Age~fitted(log1), xlab="Age", ylab="P(Survival)", pch=15)

Example: Categorical x  Sometimes, it’s easier to interpret logistic regression output if the x variables are categorical  Suppose we categorize maternal age into 3 categories: > titan$agecat4 35, c(1),c(0)) > titan$agecat3 =18 & titan$Age<=35, c(1),c(0)) > titan$agecat2 =6 & titan$Age<=17, c(1),c(0)) > titan$agecat1 <- ifelse(titan$Age<6, c(1),c(0)) Age at Death Survival< 6 years6-17 years18-35 years> 35 years No Yes

Example in R > log2<-glm(titan2$Survived~titan2$agecat2 + titan2$agecat3 + titan2$agecat4, binomial)  summary(log2)  Remember, with a set of dummy variables, you always put in one less variable than category

Example in R Call: glm(formula = titan2$Survived ~ titan2$agecat1 + titan2$agecat2 + titan2$agecat3, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) * titan2$agecat *** titan2$agecat titan2$agecat Signif. codes: 0 ‘***’ ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Null deviance: on 755 degrees of freedom Residual deviance: on 752 degrees of freedom AIC:

Interpretation: odds ratios > exp(cbind(OR=coef(log2),confint(log2))) Waiting for profiling to be done... OR 2.5 % 97.5 % (Intercept) titan2$agecat titan2$agecat titan2$agecat  This tells us that:  Passengers 35 years  Passengers in the other two age groups have no significant difference in odds of survival from passengers >35 years

Now let’s make it more complicated  Do sex and passenger class predict survival?  Let’s try a saturated model: > log3<-glm(titan$Survived~titan$Sex + titan$PClass + titan$Sex:titan$PClass, binomial) > summary(log3)

Example in R Call: glm(formula = titan$Survived ~ titan$Sex + titan$PClass + titan$Sex:titan$PClass, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) e-15 *** titan$Sexmale < 2e-16 *** titan$PClass2nd titan$PClass3rd < 2e-16 *** titan$Sexmale:titan$PClass2nd titan$Sexmale:titan$PClass3rd e-05 *** --- Signif. codes: 0 ‘***’ ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Null deviance: on 1312 degrees of freedom Residual deviance: on 1307 degrees of freedom AIC:

What variables can we consider dropping? > anova(log3,test="Chisq") Analysis of Deviance Table Response: titan$Survived Terms added sequentially (first to last) Df Deviance Resid. Df Resid. Dev P(>|Chi|) NULL titan$Sex < 2.2e-16 *** titan$PClass < 2.2e-16 *** titan$Sex:titan$PClass e-10 *** --- Signif. codes: 0 ‘***’ ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Small p-values indicate that all variables are needed to explain the variation in y

Goodness of fit statistics Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) e-15 *** titan$Sexmale < 2e-16 *** titan$PClass2nd titan$PClass3rd < 2e-16 *** titan$Sexmale:titan$PClass2nd titan$Sexmale:titan$PClass3rd e-05 *** --- Signif. codes: 0 ‘***’ ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Null deviance: on 1312 degrees of freedom Residual deviance: on 1307 degrees of freedom AIC: log L AIC

Binned residual plot install.packages("arm") library(arm) x<-predict(log3) y<-resid(log3) binnedplot(x,y) Category is based on the fitted values 95% of all values should fall within the dotted line  Plots the average residual and the average fitted (predicted) value for each bin, or category

Poisson Regression Using count data

What is a Poisson distribution?

Example: children ever born  The dataset has 70 rows representing group-level data on the number of children ever born to women in Fiji:  Number of children ever born  Number of women in the group  Duration of marriage  1=0-4, 2=5-9, 3=10-14, 4=15-19, 5=20-24, 6=25-29  Residence  1=Suva (capital city), 2=Urban, 3=Rural  Education  1=none, 2=lower primary, 3=upper primary, 4=secondary+ > ceb<-read.table("D:/RShortcourse/ceb.dat",header=T)

Poisson regression in R > ceb1<-glm(y ~ educ + res, offset=log(n), family = "poisson", data = ceb) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) <2e-16 *** educnone <2e-16 *** educsec <2e-16 *** educupper <2e-16 *** resSuva * resurban * --- Null deviance: on 69 degrees of freedom Residual deviance: on 64 degrees of freedom AIC: Inf Need to account for different population sizes in each area/group unless data are from same-size populations

Assessing model fit 1.Examine AIC score – smaller is better 2.Examine the deviance as an approximate goodness of fit test  Expect the residual deviance/degrees of freedom to be approximately 1 > ceb1$deviance/ceb1$df.residual [1] Compare residual deviance to a  2 distribution > pchisq(2646.5, 64, lower=F) [1] 0

Model fitting: analysis of deviance  Similar to logistic regression, we want to compare the differences in the size of residuals between models > ceb1<-glm(y~educ, family=“poisson", offset=log(n), data= ceb) > ceb2<-glm(y~educ+res, family=“poisson", offset=log(n), data= ceb) > 1-pchisq(deviance(ceb1)-deviance(ceb2), df.residual(ceb1)-df.residual(ceb2)) [1]  Since the p-value is small, there is evidence that the addition of res explains a significant amount (more) of the deviance

Overdispersion in Poission models  A characteristic of the Poisson distribution is that its mean is equal to its variance  Sometimes the observed variance is greater than the mean  Known as overdispersion  Another common problem with Poisson regression is excess zeros  Are more zeros than a Poisson regression would predict

Overdispersion  Use family=“quasipoisson” instead of “poisson” to estimate the dispersion parameter  Doesn't change the estimates for the coefficients, but may change their standard errors > ceb2<-glm(y~educ+res, family="quasipoisson", offset=log(n), data=ceb)

Poisson vs. quasipoisson Family = “poisson” Family = “quasipoisson” Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) <2e-16 *** educnone <2e-16 *** educsec <2e-16 *** educupper <2e-16 *** resSuva * resurban * --- (Dispersion parameter for poisson family taken to be 1) Null deviance: on 69 degrees of freedom Residual deviance: on 64 degrees of freedom Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) < 2e-16 *** educnone educsec ** educupper * resSuva resurban (Dispersion parameter for quasipoisson taken to be ) Null deviance: on 69 degrees of freedom Residual deviance: on 64 degrees of freedom

Models for overdispersion  When overdispersion is a problem, use a negative binomial model  Will adjust  estimates and standard errors > install.packages(“MASS”) > library(MASS) > ceb.nb <- glm.nb(y~educ+res+offset(log(n)), data= ceb) OR > ceb.nb<-glm.nb(ceb2) > summary(ceb.nb)

NB model in R glm.nb(formula = ceb2, x = T, init.theta = , link = log) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) < 2e-16 *** educnone educsec ** educupper resSuva resurban (Dispersion parameter for Negative Binomial(3.3872) family taken to be 1) Null deviance: on 69 degrees of freedom Residual deviance: on 64 degrees of freedom AIC: Theta: Std. Err.: x log-likelihood: > ceb.nb$deviance/ceb.nb$df.residual [1]

What if your data looked like…

Zero-inflated Poisson model (ZIP)  If you have a large number of 0 counts… > install.packages(“pscl”) > library(pscl) > ceb.zip <- zeroinfl(y~educ+res, offset=log(n), data= ceb)