rlinear-regressionpolynomialsintercept

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?


Solution

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

    should do it.

    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=...)