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.