0

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

Thanks in advance

1 Answers1

0

The help page for nlme::gls says

offset terms in model are an error since 3.1-157 (2022-03): previously they were silently ignored.

So just use the comment from user whuber, using an offset is the same as subtracting the offset term from the response. Details at Why is the plot of residuals against fitted values a horinzontal line when the dependent variable is linearly related to the indenpendent variable?