From p.dalgaard@kubism.ku.dk  Thu Apr 17 11:12:44 1997
From: p.dalgaard@kubism.ku.dk (Peter Dalgaard BSA)
Date: 17 Apr 1997 12:12:44 +0200
Subject: R-alpha: fitted = 0 of 1 in logistic regression
Message-ID: <x2d8rux8ir.fsf@bush.kubism.ku.dk>


TASK:   problem with "glm" with binomial errors
STATUS: Open
FROM:   p.dalgaard@kubism.ku.dk
        in glm(,binomial) it's possible that loss of significant
        digits make expected values 0 or 1 even though there's no
        divergence of the fit.  (Happened to me with menarche data,
        infants and grown-ups included)
        [ Need the example data.  Glm needs a complete overhaul. ]

OK, here's a way to fake some data (simulated as if menarche occurs
uniformly between 10 an 15 years of age) There's no real problem with
fitting a logistic regression to this, but the logistic curve gets too
close to 0 and 1 for the very young and the very old.

BTW: rbinom gives NA for p=0 and p=1, which causes some problems with
the simulations. 
BTW2: Doesn't "occurred" take a double r?

> fake.age<-runif(500,0,50)
> fake.menarche<-rbinom(500,1,.99999 *(fake.age > 15) + .99999 * (fake.age > 10 & fake.age <= 15)/5 * (fake.age - 10)+.000005)
> glm(fake.menarche~fake.age,binomial)
Error: fitted probabilities of 0 or 1 occured
> fake2.age<-fake.age[fake.age<25&fake.age>5]
> fake2.menarche<-fake.menarche[fake.age<25&fake.age>5]
> glm(fake2.menarche~fake2.age,binomial)

Call:  glm(fake2.menarche ~ fake2.age, binomial) 

Coefficients:
(Intercept)    fake2.age  
   -15.1061       1.2011  

Degrees of Freedom: 189 Total; 187 Residual
Null Deviance: 253.9 
Residual Deviance: 48.73 
> 


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: fitted = 0 of 1 in logistic regression
Peter Dalgaard BSA