[Rd] Possible bug in predict.lm when x is a poly

Kenny Bell kmbe||56 @end|ng |rom gm@||@com
Tue Mar 30 00:04:29 CEST 2021


Hi all,

As always, thank you all for your incredible work maintaining and improving
R.

mdl <- lm(data = mtcars,
          mpg ~ I(poly(disp, 2)))

predict(mdl, newdata = data.frame(disp = c(120, 120)))
#> Error in poly(disp, 2): 'degree' must be less than number of unique
points

predict(mdl, newdata = data.frame(disp = c(120, 121, 122)))
#>         1         2         3
#> 43.937856 12.617762  3.716257

The predict function seems to require a sufficiently high number of unique
values in newdata when the RHS is a poly. Of course, I would have expected
the output here to be:

#>         1         2
#> 43.937856 43.937856

If people agree, I can submit this to bugzilla.

Kind regards,
Kenny

	[[alternative HTML version deleted]]



More information about the R-devel mailing list