Skip to content
Prev 59674 / 398502 Next

Quadratic curve on a loop

AFAICS, there are two errors:

1. curve() is probably not what you want: it plots functions, and that's not
what predict() gives you.

2. predict() needs to be given the correct data frame: The name of the
variable(s) need to match those used in the formula.  The formula has `x' on
the righthand side, so the data frame given to predict() needs to have a
variable named `x', otherwise `x' will be looked up elsewhere, and if it
finds one, it's unlikely to be the one you intended.

Try something like:

lines(predict(out, newdata=data.frame(x=seq(min(x), max(x), length=51)))

HTH,
Andy