One could fit an exponential in many different ways. This post suggests doing the down-and-dirty lm on the log of the response variable. This SO post suggests using nls which requires a starting estimate. This SO post suggests glm with a gamma/log link function. Here, the illustrious @Glen-b explains some potential differences between approaches.
What are the pros/cons and domains of applicability for these different approaches? Do these methods differ in how well or in what way they calculate confidence intervals?
Like all the other data scientists at home right now, I'm messing around with Covid 19 data.
One thing in particular I noticed is that I can do lm with log, log10, log2 etc., but would have to convert from natural log with glm.
last_14 = data.frame(rbind(
c(3460, 14, 0),
c(3558, 17, 1),
c(3802, 21, 2),
c(3988, 22, 3),
c(4262, 28, 4),
c(4615, 36, 5),
c(4720, 40, 6),
c(5404, 47, 7),
c(5819, 54, 8),
c(6440, 63, 9),
c(7126, 85, 10),
c(7905, 108, 11),
c(8733, 118, 12),
c(9867, 200, 13)))
names(last_14) = c('World', 'US', 'days')
lm(log(World) ~ days, last_14)
#>
#> Call:
#> lm(formula = log(World) ~ days, data = last_14)
#>
#> Coefficients:
#> (Intercept) days
#> 8.06128 0.08142
glm(formula = World ~ days, data=last_14, family=gaussian(link='log'))
#>
#> Call: glm(formula = World ~ days, family = gaussian(link = "log"),
#> data = last_14)
#>
#> Coefficients:
#> (Intercept) days
#> 8.00911 0.08819
#>
#> Degrees of Freedom: 13 Total (i.e. Null); 12 Residual
#> Null Deviance: 54450000
#> Residual Deviance: 816200 AIC: 199.4
nls(World ~ exp(a + b*days), last_14, start=list(a=5, b=0.03))
#> Nonlinear regression model
#> model: World ~ exp(a + b * days)
#> data: last_14
#> a b
#> 8.00911 0.08819
#> residual sum-of-squares: 816246
#>
#> Number of iterations to convergence: 8
#> Achieved convergence tolerance: 1.25e-06
Created on 2020-03-20 by the reprex package (v0.3.0)


nlsyou can try using the formula $$a \cdot \text{exp} (b \cdot \text{days})$$ instead of $$ \text{exp} (b \cdot \text{days})$$ For instance, this code will work:nls(World ~ a*exp(b*days), last_14, start=list(a=100000, b=0.3))– Sextus Empiricus Mar 20 '20 at 21:16