R : catching errors in `nls`

后端 未结 1 1102
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 00:19

I\'m fitting some exponential data using nls.

The code I\'m using is:

fit <- nls(y ~ expFit(times, A, tau, C), start = c(A=100, tau=-         


        
1条回答
  •  一整个雨季
    2021-01-01 01:09

    I usually use this trick:

    params<-... # setup default params.
    
    while(TRUE){
    
    fit<-NULL
    try(fit<-nls(...)); # does not stop in the case of error
    
    if(!is.null(fit))break; # if nls works, then quit from the loop
    
    params<-... # change the params for nls
    
    }
    

    0 讨论(0)
提交回复
热议问题