可以用许多不同的方式拟合指数。这篇文章建议在lm响应变量的日志上做一些糟糕的事情。这个 SO post建议使用nlswhich 需要一个起始估计。这篇 SO 帖子建议glm使用 gamma/log 链接功能。在这里,杰出的@Glen-b 解释了方法之间的一些潜在差异。
这些不同方法的优点/缺点和适用范围是什么?这些方法在计算置信区间的程度或方式上是否有所不同?
像现在在家中的所有其他数据科学家一样,我正在处理 Covid 19 数据。
我特别注意到的一件事是我可以lm用log,等来做log10,log2但必须用 . 从自然对数转换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
由reprex 包(v0.3.0)于 2020-03-20 创建

