[R] How to fix slope and estimate intercept

Jun Shen jun.shen.ut at gmail.com
Thu Jul 22 21:00:25 CEST 2010


Hi, Bill,

Thanks. This is what I am looking for.

Jun

On Thu, Jul 22, 2010 at 1:54 PM, William Dunlap <wdunlap at tibco.com> wrote:
>> -----Original Message-----
>> From: r-help-bounces at r-project.org
>> [mailto:r-help-bounces at r-project.org] On Behalf Of Jun Shen
>> Sent: Thursday, July 22, 2010 10:30 AM
>> To: R-help
>> Subject: [R] How to fix slope and estimate intercept
>>
>> Dear all,
>>
>> Is there anyway I can fix slope in some value and only estimate
>> intercept for a linear regression? I understand lm(y~1, data) will NOT
>> have a slope at all. This is not what I want. Thanks.
>
> You can use an offset() term in your formula.  E.g.,
>  > x <- log(1:10)
>  > y <- 2.7*x + 3.4
>  > lm(y ~ 1 + offset(2.7*x))
>
>  Call:
>  lm(formula = y ~ 1 + offset(2.7 * x))
>
>  Coefficients:
>  (Intercept)
>          3.4
>
>  > lm(y ~ 1 + offset(2.6*x))
>
>  Call:
>  lm(formula = y ~ 1 + offset(2.6 * x))
>
>  Coefficients:
>     (Intercept)
>  3.551044125731
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>>
>> Jun
>>
>> ______________________________________________
>> 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.
>>
>



More information about the R-help mailing list