# How to fit a gls model with a known slope

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

set.seed(6)

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

y <- 2 + x + rnorm(100)

library(nlme)

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

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

gls2<-gls(y ~ 1)

coef(lm1);coef(gls1);coef(gls2)

coef(lm1)

(Intercept) 1.606107

coef(gls1)

(Intercept) 2.078286

coef(gls2)

(Intercept) 2.078286

• Try gls(y - 2.5*x ~ 1) – whuber Mar 29 at 18:48