[R] nls fit to exponential decay with unknown time origin

Robert D. Merithew merithew at ccmr.cornell.edu
Fri Dec 14 20:06:43 CET 2001



I'm trying to use nls() to fit an exponential decay with an unknown offset
in the time (independent variable).  (Perhaps this is inherently very
difficult?).


> decay.pl <- nls (amp ~ expn(b0,b1,tau,t0,t), data = decay,
+                  start = c(b0=1, b1=7.5, tau=3.5, t0=0.1), trace=T)
Error in nlsModel(formula, mf, start) : singular gradient matrix at
initial parameter estimates
> 
> expn(1, 7.5, 3.5, 0.1, decay$t)
[1] 6.636080 5.259657 4.164661 2.797383 1.760584 1.250300
attr(,"gradient")
     b0         b1        tau         t0
[1,]  1 0.75147729 -0.4600881 1.61030849
[2,]  1 0.56795432 -0.6884997 1.21704497
[3,]  1 0.42195477 -0.7801858 0.90418880
[4,]  1 0.23965104 -0.7336256 0.51353794
[5,]  1 0.10141123 -0.4973290 0.21730978
[6,]  1 0.03337327 -0.2431481 0.07151415
> 


Is the gradient matrix really singular?  It works without the t0
parameter.


Code follows (after MASS 2nd ed. p. 271):

----------

require(nls)

t <- c(1.1,2.08,3.12,5.1,8.11,12)
amp <- c(7.4, 6.1, 4.95, 3.5, 2.3, 1.5)
decay <- data.frame (t = t, amp = amp)

expn <- function (b0, b1, tau, t0, t) {
  temp <- exp((t0-t)/tau)
  model.func <- b0 + b1 * temp
  Z <- cbind(1, temp, (b1 * (t0-t) * temp) / tau^2, b1 * temp / tau)
  dimnames(Z) <- list(NULL, c("b0","b1","tau","t0"))
  attr(model.func, "gradient") <- Z
  model.func
}

decay.pl <- nls (amp ~ expn(b0,b1,tau,t0,t), data = decay,
                 start = c(b0=1, b1=7.5, tau=3.5, t0=0.1), trace=T)

----------

thanks,
--
Robert Merithew
Laboratory of Atomic and Solid State Physics, Clark Hall
Cornell University, Ithaca, NY

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list