Search code examples
statisticscurve-fittingmodelingexponentialdata-fitting

exponential growth function in R - fitting data


I have the following data:

> x = 1:40
> y =
 5    6   28   30   31   34   39   48   63   70   82   91  107  112  127  146  171  198  258  334  403  497  571  657  730  883 1024 1139
1329 1635 2059 2545 3105 3684 4289 4778 5351 5916 6729 7600

enter image description here

How can I figure out the exponential function (including the coefficients and constants) of this graph in R?


Solution

  • In your post you have only 38 values for y, so i basically assume x to be 1:38. If y = exp(ax+b), you can change it to log(y) = ax + b and fit a linear model. The below will work with the correct values:

    x = 1:38
    y = c(5, 6, 28, 30, 31, 34, 39, 48, 63, 70, 82, 91, 107, 112, 127, 
    146, 171, 198, 258, 334, 403, 497, 571, 657, 730, 883, 1024, 
    1635, 2059, 2545, 3105, 3684, 4289, 4778, 5351, 5916, 6729, 7600
    )
    
    fit = lm(log(y) ~ x)
    plot(x,y)
    lines(x,exp(fitted(fit)),col="blue")
    

    enter image description here