ToonVanDaele / trias-test

test repository ofr trias
0 stars 0 forks source link

Warning message about convergence #8

Closed damianooldoni closed 4 years ago

damianooldoni commented 4 years ago

I get this warning while applying GAM to "lumped" data of taxonKey 1713034 using method GAM_lcount_cobs:

Warning message:
In newton(lsp = lsp, X = G$X, y = G$y, Eb = G$Eb, UrS = G$UrS, L = G$L,  :
  Iteration limit reached without full convergence - check carefully

Is this something should we worry about it?

ToonVanDaele commented 4 years ago

It means the model didn't converge to meaningfull model parameters. Most probably due to poor data. Right now the algorithm will return 'unclear'. It's better to return 'NA'. I'll adapt the spGAMxxx functions

damianooldoni commented 4 years ago

To do this, I suggest to use tryCatch then. As up to now the try() doesn't catch any warning. See example:

x <- function(i){
  if (i < 10) warning("A warning")
  i
}

tt <- tryCatch(x(5),error=function(e) e, warning=function(w) w)

tt2 <- tryCatch(x(15),error=function(e) e, warning=function(w) w)

More about this example in StackOverflow link.

Doing it with a try() is also possible (see solution in same link), but we will not have a difference in output between warning and error, and the solution is quite ugly, I find.

damianooldoni commented 4 years ago

@ToonVanDaele : I am implementing it in this way, maybe you can find it useful:

result <- tryCatch(expr = {
  model <- gam(formula = fm,
               family = nb(),
               data = df,
               method = "REML")
  }, error=function(e) e, warning=function(w) w)
#.... some other code...
if (class(result)[1] %in% c("simpleWarning", "simpleError")) {

} else {
}
damianooldoni commented 4 years ago

On my laptop I need tryCatch to avoid using GAM output if warning arises. Still, close this issue if you solved it.

ToonVanDaele commented 4 years ago

changed try to tryCatch. Works fine now. Thanks.