Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitting a polynomial with a known intercept

I am using lm(y~poly(x,2)) to fit a second-order polynomial to my data. But I just couldn't find a way to specify a known intercept value. How can I fit a polynomial model with a known intercept value (say 'k') using lm?

like image 979
rm167 Avatar asked Feb 13 '15 14:02

rm167


People also ask

How do you fit a polynomial into Origin?

To force the fitted curve go through Origin (0,0), you can just fix the intercept to 0 for a linear or polynomial model. To force the fitted curve go through a specific point in raw data, you can set a higher weight for the point.

What is degree of fitting polynomial?

The first degree polynomial equation. is a line with slope a. A line will connect any two points, so a first degree polynomial equation is an exact fit through any two points with distinct x coordinates.


1 Answers

 lm(y~-1+x+I(x^2)+offset(k))

should do it.

  • -1 suppresses the otherwise automatically added intercept term
  • x adds a linear term
  • I(x^2) adds a quadratic term; the I() is required so that R interprets ^2 as squaring, rather than taking an interaction between x and itself (which by formula rules would be equivalent to x alone)
  • offset(k) adds the known constant intercept

I don't know whether poly(x,2)-1 would work to eliminate the intercept; you can try it and see. Subtracting the offset from your data should work fine, but offset(k) might be slightly more explicit. You might have to make k a vector (i.e. replicate it to the length of the data set, or better include it as a column in the data set and pass the data with data=...

like image 160
Ben Bolker Avatar answered Sep 29 '22 13:09

Ben Bolker