i want to fit a gls model (from nlme package) with a specified slope, so i can get the computed intercept for the best fit. I tried to set the slope with an offset. Althogh it works fine with lm, it seems to get ignored when using gls (which i need to, sence my dataset presents heteroscedasticity).

Here is an example (lets say the known slope is 2.5).


x <- runif(100, -3, 3)

y <- 2 + x + rnorm(100)


lm1<-lm(y ~ offset(x*2.5))

gls1<-gls(y ~ offset(x*2.5))

gls2<-gls(y ~ 1)



(Intercept) 1.606107


(Intercept) 2.078286


(Intercept) 2.078286

Thanks in advance

  • 3
    $\begingroup$ Try gls(y - 2.5*x ~ 1) $\endgroup$ – whuber Mar 29 at 18:48
  • $\begingroup$ @whuber It worked perfectly. Thank you very much for your answer. $\endgroup$ – Enrique Otero Apr 1 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.