From murdoch@stats.uwo.ca  Tue Sep 25 14:52:53 2001
From: murdoch@stats.uwo.ca (murdoch@stats.uwo.ca)
Date: Tue, 25 Sep 2001 15:52:53 +0200 (MET DST)
Subject: [Rd] Bug in model.matrix.default (was: [R] predict incosistency ?) (PR#1100)
Message-ID: <200109251352.PAA21550@pubhealth.ku.dk>

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


[Rd] Bug in model.matrix.default (was: [R] predict incosistency ?) (PR#1100)
murdoch@stats.uwo.ca