[R] how fit linear model with fixed slope?

2010-10-22 Thread Czerminski, Ryszard
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@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.


Re: [R] how fit linear model with fixed slope?

2010-10-22 Thread Dimitris Rizopoulos

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@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/

__
R-help@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.


Re: [R] how fit linear model with fixed slope?

2010-10-22 Thread Douglas Bates
On Fri, Oct 22, 2010 at 9:13 AM, Czerminski, Ryszard
ryszard.czermin...@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))

__
R-help@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.


Re: [R] how fit linear model with fixed slope?

2010-10-22 Thread Masca, Nicholas
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Czerminski, Ryszard
Sent: 22 October 2010 15:14
To: r-help@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}}

__
R-help@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.