[R] exponential fitting

Gabor Grothendieck ggrothendieck at gmail.com
Wed Sep 27 15:05:53 CEST 2006


> # using this test data
> set.seed(1)
> x <- 1:20/20
> y <- exp(2 + 3 * x) + rnorm(20)
>
> # if its ok to fit logs so that its linear
> exp(fitted(lm(log(y) ~ x)))
        1         2         3         4         5         6         7         8
  8.55615   9.94692  11.56376  13.44340  15.62857  18.16894  21.12223  24.55557
        9        10        11        12        13        14        15        16
 28.54699  33.18720  38.58165  44.85295  52.14363  60.61938  70.47284  81.92793
       17        18        19        20
 95.24501 110.72673 128.72494 149.64869
>
> # or to do it on original scale use linear coefs as starting values
> cc <- coef(lm(log(y) ~ x))
> fitted(nls(y ~ exp(a + b*x), start = list(a = cc[1], b = cc[2])))
 [1]   8.592270   9.984536  11.602401  13.482421  15.667073  18.205720
 [7]  21.155722  24.583734  28.567211  33.196159  38.575168  44.825776
[13]  52.089214  60.529599  70.337640  81.734946  94.979039 110.369167
[19] 128.253066 149.034820
attr(,"label")
[1] "Fitted values"

On 9/27/06, jessica.gervais at tudor.lu <jessica.gervais at tudor.lu> wrote:
> Hi,
>
> I would like to fit some experimental points by a exponential function.
> I ignore the parameters of this exponential and what I would like is to
> ask R to calculate the best fitting curve an the associated parameters (as
> the linear model function (lm) does for linear models).
> Is it possible ?
> Do anyone have an idea about how to do that ?
>
> Thanks by advance
>
> Jessica Gervais
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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