[Rd] Inconsistency, possibly a bug? (PR#758)
presnell@stat.ufl.edu
presnell@stat.ufl.edu
Tue, 5 Dec 2000 01:26:51 +0100 (MET)
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?
--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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._