Re: [R] how to compute maximum of fitted polynomial?

2013-06-05 Thread David Winsemius
On Jun 4, 2013, at 10:15 PM, Hans W Borchers wrote: Bert Gunter gunter.berton at gene.com writes: 1. This looks like a homework question. We should not do homework here. 2. optim() will only approximate the max. 3. optim() is not the right numerical tool for this anyway. optimize() is.

Re: [R] how to compute maximum of fitted polynomial?

2013-06-05 Thread Hans W Borchers
David Winsemius dwinsemius at comcast.net writes: [...] On Jun 4, 2013, at 10:15 PM, Hans W Borchers wrote: In the case of polynomials, elementary math ... methods can actually be executed with R: library(polynomial) # -6 + 11*x - 6*x^2 + x^3 p0 -

Re: [R] how to compute maximum of fitted polynomial?

2013-06-05 Thread Joseph Clark
Thank you all! This approach, using the 'polynom' library, did the trick. library(polynom) # -6 + 11*x - 6*x^2 + x^3 p0 - polynomial(c(-6, 11, -6, 1)) # has zeros at 1, 2, and 3 p1 - deriv(p0); p2 - deriv(p1) # first and second derivative xm - solve(p1) # maxima and minima of p0 xmax =

[R] how to compute maximum of fitted polynomial?

2013-06-04 Thread Joseph Clark
My script fits a third-order polynomial to my data with something like this: model - lm( y ~ poly(x, 3) ) What I'd like to do is find the theoretical maximum of the polynomial (i.e. the x at which model predicts the highest y). Specifically, I'd like to predict the maximum between 0 = x = 1.

Re: [R] how to compute maximum of fitted polynomial?

2013-06-04 Thread Rui Barradas
Hello, As for the first question, you can use ?optim to compute the maximum of a function. Note that by default optim minimizes, to maximize you must set the parameter control$fnscale to a negative value. fit - lm(y ~ poly(x, 3)) fn - function(x, coefs) as.numeric(c(1, x, x^2, x^3) %*%

Re: [R] how to compute maximum of fitted polynomial?

2013-06-04 Thread Bert Gunter
1. This looks like a homework question. We should not do homework here. 2. optim() will only approximate the max. 3. optim() is not the right numerical tool for this anyway. optimize() is. 4. There is never a guarantee numerical methods will find the max. 5. This can (and should?) be done

Re: [R] how to compute maximum of fitted polynomial?

2013-06-04 Thread Hans W Borchers
Bert Gunter gunter.berton at gene.com writes: 1. This looks like a homework question. We should not do homework here. 2. optim() will only approximate the max. 3. optim() is not the right numerical tool for this anyway. optimize() is. 4. There is never a guarantee numerical methods will find