> Take a look at the predicted values at your starting fit:  there's a 
> discontinuity at 0.4, which sure makes it look as though overflow is 
> occurring.  I'd recommend expanding tanh() in terms of exponentials and 
> rewrite the prediction in a way that won't overflow.
>
> Duncan Murdoch

Hi Duncan,
Thank you for your suggestion. I wrote a function "mytanh" and 
nls terminates a bit later with another error message:

Error in nls(data = dd, y ~ 1/2 * (1 - mytanh((x - ttt)/1e-04) * exp(-x/tau2)), 
 : 
  number of iterations exceeded maximum of 50

How can i fix that?
Kind regards,
Jonas

============================ R CODE STARTS HERE =======

mytanh <- function(x){
  return(x - x^3/3 + 2*x^5 /15 - 17 * x^7/315)
}

t <- seq(0,1,0.001)
t0 <- 0.5
tau1 <- 0.02

yy <- 1/2 * ( 1- tanh((t - t0)/0.0001) * exp(-t / tau1) ) + 
rnorm(length(t))*0.001

plot(x=t, y=yy, pch=18)

dd <- data.frame(y=yy, x=t)

nlsfit <- nls(data=dd,  y ~  1/2 * ( 1- mytanh((x - ttt)/0.0001) * exp(-x / 
tau2) ), start=list(ttt=0.5, tau2=0.02) , trace=TRUE)

============================ R CODE ENDS HERE =======

-- 
Jonas Stein <n...@jonasstein.de>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to