Hi, Bill, Thanks. This is what I am looking for.
Jun On Thu, Jul 22, 2010 at 1:54 PM, William Dunlap <wdun...@tibco.com> wrote: >> -----Original Message----- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@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@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. >> > ______________________________________________ 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.