简体   繁体   中英

regression of exponential decay data using nls

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.

You can re-specify the model by taking the log of both sides to get the same coefficients but with more realistic confidence intervals:

library(nlstools)

## Run the nls model for exponential decay
model <- nls(log(count) ~ log(b0) - b1 * week,
             start = list(b0 = intercpt,
                          b1 = coeff),
             trace=T,
             data = df)
#> 1083.602    (1.70e+01): par = (1712732584 -6.707821)
#> 3.725045    (1.41e-07): par = (1712732584 6.707821)

## 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]

log(2)/b1
#>        b1 
#> 0.1033342
log(2)/high
#> [1] 0.09522392
log(2)/low
#> [1] 0.1129546

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 over lm here.

Created on 2022-06-21 by the reprex package (v2.0.1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM