[Rd] Bug in model.matrix.default (PR#1100)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Tue, 25 Sep 2001 15:57:11 +0200 (MET DST)


There's more to it than that (which was already fixed in R-devel).
The internal code expects there to be columns in the model frame.

I have already fixed this in R-devel (by faking an unused column).


On Tue, 25 Sep 2001 murdoch@stats.uwo.ca wrote:

> On Tue, 25 Sep 2001 12:27:27 GMT, Jorge Luis Ojeda Cabrera
> <jojeda@posta.unizar.es> wrote in message
> <20010925.12272700@macdesp8.unizar.es>:
>
> >When fitting model 'y~1', the 'lm' response is ok, but it is not possible
> >to get predictions using 'predict'. May be this is a bug, at least i
> >think it is somehow
> >inconsistent.
>
> It still appears in 1.3.1, I think it's a bug.  It shows up when you
> use the newdata parameter to predict.lm; if you just ask for
> predictions without specifying the x value things are fine:
>
> > d _ data.frame(x=runif(5),y=runif(5))
> > d1.lm _ lm(y ~ 1, data=d)
> >
> > #  This one is okay:
> >
> > predict(d1.lm)
>        1        2        3        4        5
> 0.486269 0.486269 0.486269 0.486269 0.486269
> >
> > # This one triggers the bug:
> >
> > predict(d1.lm,newdata=data.frame(x=0.5))
> Error in model.matrix.default(delete.response(tt), newdata, contrasts
> = object$contrasts,  :
>         subscript out of bounds
>
> There are 3 lines in model.matrix.default that assume that there is at
> least one predictor in the model:  they index various things by "-1"
> to remove it.  I can't follow what's going on there well enough to fix
> it.
>
> Duncan Murdoch
>
> Version:
>  platform = i386-pc-mingw32
>  arch = x86
>  os = Win32
>  system = x86, Win32
>  status =
>  major = 1
>  minor = 3.1
>  year = 2001
>  month = 08
>  day = 31
>  language = R
>
> Windows 98 4.10 (build 1998)
>
> Search Path:
>  .GlobalEnv, package:ctest, Autoloads, package:base
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._