使用NLS回归指数衰减数据
我从该模型中获得了衰减参数的负估计。特别是较低的置信区间。我怀疑我正在错误地计算CI或错误指定该模型:
library(nlstools)
## example data
df <- data.frame(week = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L),
count = c(1.3e+09, 9e+08, 4e+09, 1.7e+09, 1.2e+09,
3e+09, 1.58e+09, 1.6e+09, 3e+09, 1e+09,
1100000, 2e+06, 1700000, 4e+06, 1400000,
4e+06))
## taking log to get starting values for nls
model_lm <- lm(log(count)~week, data = df)
## extract the coefficients and to convert values back to non-log
intercpt <- exp(model_lm$coefficients[1])
coeff<- model_lm$coefficients[2]
## Run the nls model for exponential decay
model <- nls(count ~ b0 * exp(-b1 * week),
start = list(b0 = intercpt,
b1 = coeff),
trace=T,
data = df)
## Point estimate of decay parameter
b1 <- coef(model)[2]
## 95% CI for the decay parameter
low <- confint2(model)[2,1]
high <- confint2(model)[2,2]
## What is the half life ?
log(2)/b1
log(2)/high
log(2)/low
## The result of half life doesn't make sense. The CI for half life
## includes 0. You cannot have a negative half life. The CI also does
## not include the point estimate.
I am getting negative estimates of the decay parameter from this model. Specifically the lower confidence interval. I suspect I am calculating the CI incorrectly or mis-specifying the model:
library(nlstools)
## example data
df <- data.frame(week = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L),
count = c(1.3e+09, 9e+08, 4e+09, 1.7e+09, 1.2e+09,
3e+09, 1.58e+09, 1.6e+09, 3e+09, 1e+09,
1100000, 2e+06, 1700000, 4e+06, 1400000,
4e+06))
## taking log to get starting values for nls
model_lm <- lm(log(count)~week, data = df)
## extract the coefficients and to convert values back to non-log
intercpt <- exp(model_lm$coefficients[1])
coeff<- model_lm$coefficients[2]
## Run the nls model for exponential decay
model <- nls(count ~ b0 * exp(-b1 * week),
start = list(b0 = intercpt,
b1 = coeff),
trace=T,
data = df)
## Point estimate of decay parameter
b1 <- coef(model)[2]
## 95% CI for the decay parameter
low <- confint2(model)[2,1]
high <- confint2(model)[2,2]
## What is the half life ?
log(2)/b1
log(2)/high
log(2)/low
## The result of half life doesn't make sense. The CI for half life
## includes 0. You cannot have a negative half life. The CI also does
## not include the point estimate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过删除双方的日志以获得相同的系数,但要使用更现实的置信区间来重新指定模型:
我不确定您为什么在初始模型中遇到问题,但我怀疑该模型中的巨大残留物非努力转换数据是原因。
无论哪种情况,我都不确定通过
lm
在此处使用nls
获得什么。由
You can re-specify the model by taking the log of both sides to get the same coefficients but with more realistic confidence intervals:
I'm not entirely sure why you get the problem with your initial model, but I suspect the huge residuals in the non-log transformed data are the cause.
In either case, I'm not sure what you gain by using
nls
overlm
here.Created on 2022-06-21 by the reprex package (v2.0.1)