[Rd] Inconsistency, possibly a bug? (PR#758)
Prof Brian D Ripley
ripley@stats.ox.ac.uk
Tue, 5 Dec 2000 07:51:16 +0000 (GMT)
On Tue, 5 Dec 2000 presnell@stat.ufl.edu wrote:
>
> Seems to be a day for finding peculiar little things. There is an
> inconsistency in the behavior of lm vis a vis glm:
>
> > x <- rnorm(15)
> > y <- 1 + 10*x + rnorm(15)
> > z <- as.factor(rep(c("A","B","C"),rep(5,3)))
> > xyz <- data.frame(x,y,z)
> > fit.lm <- lm(y ~ x + z, data=xyz, subset=(z != "C"))
> > fit.glm <- glm(y ~ x + z, family=gaussian, data=xyz, subset=(z != "C"))
> > zz <- z[1:10]
> > xx <- rnorm(10)
> > predict(fit.lm,data.frame(x=xx,z=zz))
> Error in model.frame.default(formula, data, xlev = xlev) :
> factor z has new level(s) C
> > predict(fit.glm,data.frame(x=xx,z=zz))
> 1 2 3 4 5 6
> 2.570970 -18.007372 18.108771 12.498562 9.566029 10.518460
> 7 8 9 10
> -9.132206 11.440242 -16.054621 -3.017842
>
>
> This happens because of the line
>
> mf$drop.unused.levels <- TRUE
>
> in lm and the lack of same in glm. I'm reporting this as a bug, but
> perhaps the difference is intentional?
No, as the glm code is not protected from user error as the lm code is. I
am not sure it is bug (it's not documented to happen) and probably there
are several related occurrences in other modelling functions, but it would
be a desirable addition and I will change it for glm (at least).
>
> --please do not edit the information below--
>
> Version:
> platform = sparc-sun-solaris2.6
> arch = sparc
> os = solaris2.6
> system = sparc, solaris2.6
> status =
> major = 1
> minor = 1.1
> year = 2000
> month = August
> day = 15
> language = R
>
> Search Path:
> .GlobalEnv, Autoloads, package:base
>
> --
> Brett Presnell
> Department of Statistics
> University of Florida
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._