Skip to content
Prev 262516 / 398502 Next

NLS fit for exponential distribution

On Sun, 12 Jun 2011, peter dalgaard wrote:

            
OK, that makes more sense. Also, scaling of the variables may help. 
Something like this could work:

## scaled data
d <- data.frame(x = c(1, 1:10 * 10), y = 100 *  c(
   0.033823, 0.014779, 0.004698, 0.001584, -0.002017, -0.003436, -0.000006,
   -0.004626, -0.004626, -0.004626, -0.004626))

## model fits
n1 <- nls(y ~ a*exp(-m * x) + b, data = d,
   start = list(a = 1, b = 0, m = 0.1))
n2 <- nls(y ~ a * (exp(-m1 * x) + exp(-m2 * x)) + b, data = d,
   start = list(a = 1, b = 0, m1 = 0.1, m2 = 0.5))

## visualization
plot(y ~ x, data = d)
lines(d$x, fitted(n1), col = 2)
lines(d$x, fitted(n2), col = 4)

## ANOVA
anova(n1, n2)

## LR test
library("lmtest")
lrtest(n1, n2)

which both seem to indicate that n1 is sufficient.

hth,
Z