I want to fit a linear model with fixed slope e.g. y = x + b (instead of general: y = a*x + b) Is it possible to do with lm()? Regards, Ryszard -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may ...{{dropped:11}}
yes, you can use an offset, e.g., x <- runif(100, -3, 3) y <- 2 + x + rnorm(100) lm(y ~ x) lm(y ~ offset(x)) I hope it helps. Best, Dimitris On 10/22/2010 4:13 PM, Czerminski, Ryszard wrote:> I want to fit a linear model with fixed slope e.g. y = x + b > (instead of general: y = a*x + b) > > Is it possible to do with lm()? > > Regards, > Ryszard > > > -------------------------------------------------------------------------- > Confidentiality Notice: This message is private and may ...{{dropped:11}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
Hi, It looks to me like you want to fit x as an offset (i.e. a variable with a fixed gradient of 1). If so, simply do: lm(y~1+offset(x)) #for a model with an intercept or lm(y~-1+offset(x)) #for a model with no intercept Cheers, Nick -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Czerminski, Ryszard Sent: 22 October 2010 15:14 To: r-help at r-project.org Subject: [R] how fit linear model with fixed slope? I want to fit a linear model with fixed slope e.g. y = x + b (instead of general: y = a*x + b) Is it possible to do with lm()? Regards, Ryszard -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may ...{{dropped:9}}
On Fri, Oct 22, 2010 at 9:13 AM, Czerminski, Ryszard <Ryszard.Czerminski at astrazeneca.com> wrote:> I want to fit a linear model with fixed slope e.g. y = x + b > (instead of general: y = a*x + b)> Is it possible to do with lm()?Yes. The simplest way is to fit lm(y - a*x ~ 1) which will give you the estimate of b, its standard error, etc. An alternative is to use an offset argument or an offset() expression in the model formula lm(y ~ 1 + offset(a*x))