Skip to content

predict function (PR#2958)

2 messages · mh.smith@niwa.co.nz, Brian Ripley

#
Full_Name: Murray H Smith
Version: 1.6.1
OS: Windows
Submission from: (NULL) (202.36.29.1)


This is report is more of a matter of completeness rather than an outright bug.
The predict function does not handle the prediction from the constant model
appropriately. It also differs from Splus in this respect.

The length of the vector (or first dimension of the matrix, if type = "terms" is
used) for the output from the predict function should equal the number of rows
in newdata, whether or not the model is the constant model.
+   newdata = data.frame(x = 1:5))  
[1] 1.181818
+   rep(0:3, c(5,9,7,1)))), newdata = data.frame(x = 1:5), type = "r")  
[1] 1.181818

Since there are 5 rows in the newdata data.frame the result should be the vector
of length 5.

[1] 1.181818  1.181818  1.181818  1.181818  1.181818

.

As an aside it might also be nice to also avoid having to deal with a special
case by defaulting the model formula

    ~ poly(x, 0)

to

    ~ 1

with perhaps a warning rather than producing an error.
#
Try
NULL data frame with 1 rows

The C code never considers that case (no variables).

Fixed in R-patched.
On Thu, 8 May 2003 mh.smith@niwa.co.nz wrote:

            
Still in 1.7.0, BTW, but we do suggest you upgrade as scores of bugs have 
been fixed since 1.6.1.
That's not so easy. The formula really is ~ 1 + poly(x, d), and there is 
no simple way to have a term which contributes nothing.  poly(x, 0) could 
be a zero-column matrix, but the subsequent code will not handle that.

It's much easier for you to handle redundant terms yourself.