Sebastian Leuzinger
2004-Oct-27 08:26 UTC
[R] predicting x values in a polynomial regression
Dear R I would like to predict x-values in a 4th order polynomial regression: x <- c(1:10) y <- c(2,7,19,49,89,94,97,98,92,89) # these are percentages lm(y ~ x+I(x^2)+I(x^3)+I(x^4)-1) -> lm1 now I would like to know what the model fit (x-value) for y=50 is. This results in solving a 4th order quadratic equation. polyroot() does not really help because it only gives me the x-values for y=0. I have tried with nls() which sort of works, but I am sure there is a much easier solution to that, can anyone give me a hint? -- Sebastian Leuzinger Institute of Botany, University of Basel Sch??nbeinstr. 6 CH-4056 Basel Ph. 0041 (0) 61 267 3511 fax 0041 (0) 61 2673504 email: Sebastian.Leuzinger at unibas.ch <mailto:Sebastian.Leuzinger at unibas.ch> web: unibas.ch/botschoen/leuzinger/e.shtml <unibas.ch/botschoen/leuzinger/d.shtml>
Sebastian Leuzinger wrote:> Dear R > > I would like to predict x-values in a 4th order polynomial regression: > > x <- c(1:10) > y <- c(2,7,19,49,89,94,97,98,92,89) # these are percentages > > lm(y ~ x+I(x^2)+I(x^3)+I(x^4)-1) -> lm1 > > now I would like to know what the model fit (x-value) for y=50 is. This > results in solving a 4th order quadratic equation. polyroot() does not > really help because it only gives me the x-values for y=0. I have tried > with nls() which sort of works, but I am sure there is a much easier > solution to that, can anyone give me a hint?What about optim()? Uwe Ligges
Prof Brian Ripley
2004-Oct-27 09:04 UTC
[R] predicting x values in a polynomial regression
On Wed, 27 Oct 2004, Sebastian Leuzinger wrote:> I would like to predict x-values in a 4th order polynomial regression: > > x <- c(1:10) > y <- c(2,7,19,49,89,94,97,98,92,89) # these are percentages > > lm(y ~ x+I(x^2)+I(x^3)+I(x^4)-1) -> lm1 > > now I would like to know what the model fit (x-value) for y=50 is. This > results in solving a 4th order quadratic equation. polyroot() does not > really help because it only gives me the x-values for y=0.And what are the roots of p(x) - 50?> I have tried with nls() which sort of works, but I am sure there is a > much easier solution to that, can anyone give me a hint?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, stats.ox.ac.uk/~ripley University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595