bug in glm (PR#397)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Mon, 10 Jan 2000 13:33:13 +0100 (MET)


> Date: Mon, 10 Jan 2000 11:53:50 +0100 (MET)
> From: holzer@stat.math.ethz.ch
> 
> Dear R-team
> 
> As I didn't get any answer to my bug-report last week I have taken the
> effort and extracted a minimal data set from my data (see below) where the
> following bug occurs:
> 
> > glm(SKR.ein.aus ~ ., family = binomial, data = bugdata, na.action = na.omit)
> Error in names<-.default(*tmp*, value = ynames) : names attribute must be the 
same length as the vector
> In addition: Warning messages: 
> 1: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 2: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 3: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 4: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 5: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 6: fitted probabilities of 0 or 1 occurred in: (if (is.empty.model(mt)) 
glm.fit.null else glm.fit)(x = X, y = Y,  
> 7: Algorithm did not converge in: (if (is.empty.model(mt)) glm.fit.null else 
glm.fit)(x = X, y = Y,  
> 
> 
> "bugdata" <-
> structure(list(TAGNR = c(1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 
> 16, 17, 18, 19, 20, 21, 22, 23, 24), FAC.A1 = c(1.890074713, 
> 0.285627892, -0.728152664, 0.117508066, -0.316988379, -0.614649045, 
> -0.969428677, -0.036, -0.139119729, -0.25405231, -0.278163883, 
> 0.296010189, 0.290285736, -0.036, -0.304357608, -0.129913755, 
> -0.136209139, -0.290925392, 0.219392415, 0.418347431), FAC.A2 = c(1.626524757, 
> 0.447314597, 0.401823062, 0.161047605, 0.470022244, -1.227729293, 
> -0.702664589, 0.065, -0.477090522, -0.464008109, -0.264137857, 
> 0.576270516, 1.157658697, 0.065, -0.018453905, -3.059806667, 
> 0.694435007, 0.074223629, 1.115136699, 0.652975139), MLDR = c(9529, 
> 9637, 9605, 9631, 9674, 9636, 9640, 9733, 9734, 9726, 9747, 9643, 
> 9593, 9582, 9699, 9810, 9820, 9813, 9824, 9840), MWSQUAL = c(5, 
> 1, 7.5, 7, 0.5, 6, 6, 8, 7, 6, 7, 7, 7, 8, 8, 7, 7, 7, 7, 8), 
>     FAC.M1 = c(0.346099763, -1.404917729, -0.122803627, -1.105302108, 
>     -0.820151926, -0.148255768, -0.059281084, -0.177, -0.597900864, 
>     -0.385193779, 0.576167774, -0.213567265, -0.087008627, -0.150494043, 
>     0.061886447, -0.000514461, 0.52592456, 0.25696687, 0.119899896, 
>     -0.158271395), FAC.M2 = c(0.509341516, -1.28717534, 0.484499473, 
>     0.609920083, -1.049431096, 0.523520113, 0.00821345, -0.096, 
>     -1.526343789, -0.698071247, 0.404253968, 0.384329318, -0.354346109, 
>     0.43895688, -2.077185788, -1.044851055, 0.623330523, 0.791948597, 
>     1.120535816, 0.314008432), SKR.ein.aus = c(0, 1, 1, 1, 1, 
>     0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0)), .Names = c("TAGNR", 
> "FAC.A1", "FAC.A2", "MLDR", "MWSQUAL", "FAC.M1", "FAC.M2", "SKR.ein.aus"
> ), row.names = c("139", "140", "141", "142", "143", "144", "145", 
> "146", "147", "148", "149", "150", "151", "152", "153", "154", 
> "155", "156", "157", "158"), class = "data.frame")
> 
> 
> I hope, this makes it possible to find the bug.

Indeed, thank you (we needed an example). Alter

    names(w) <- ynames
    
to
    names(w) <- ynames[good]

and

    names(fit$effects) <-
	c(xxnames[seq(fit$rank)], rep("", nobs - fit$rank))

to 
    names(fit$effects) <-
	c(xxnames[seq(fit$rank)], rep("", sum(good) - fit$rank))

as the vector w is dropping observations with fitted probs 0 or 1.

Brian Ripley

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._