Hello, I'm using the following for loop to find regression curves using a list of functions (formList), a list of starting values (startList), uppervalues (upperList) and lower values (lowerList). A sample of the list of function I use in the loop is the following: FormList <- list(PTG.P ~ fz1(Portata, a, b), PTG.P ~ fz2(Portata, a, b), PTG.P ~ fz3(Portata,a, b, d, e), PTG.P ~ fz4(Portata, a, b), PTG.P ~ fz5(Portata, a, b, d), PO4.P ~ fz1(Portata, a, b), PO4.P ~ fz2(Portata, a, b), ... And the loop I use is: resultList <- list() for (i in 1:length(formList)) { resultList[[i]] <- nls(formList[[i]], data=subset(dati, Fiume=="Laveggio"), start=startList[[i]], nls.control(maxiter=1000, warnOnly=TRUE), algorithm='port', na.action=na.omit,lower=lowerList[[i]], upper=upperList[[i]]) } When the computation ends I get 5 warning messages (one of false convergence, 4 of singular convergence: In nls(formList[[i]], data = subset(dati, Fiume == "Laveggio"), : Convergence failure: false convergence (8) 2: In nls(formList[[i]], data = subset(dati, Fiume == "Laveggio"), : Convergence failure: singular convergence (7) If I want to get the summary of the first object of the resultList I do: summary(resultList[[1]]) And I get a result with no problem: Formula: PTG.P ~ fz1(Portata, a, b) Parameters: Estimate Std. Error t value Pr(>|t|) a 61.158 18.591 3.290 0.00140 ** b 7.616 8.720 0.873 0.38464 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Residual standard error: 91.32 on 96 degrees of freedom Algorithm "port", convergence message: both X-convergence and relative convergence (5) It also works if I try to get the summary of the first 5 object of the resultList with: summaryList<-list() for (i in 1:5) { summaryList[[i]]<-summary(resultList[[i]]) } But if I try to get the summary of all the objects of the resultList (there are 35 objects) it doesn't work... I tried: summaryList<-list()> for (i in 1:length(resultList))+ { + summaryList[[i]]<-summary(resultList[[i]]) + } And I got the following error message: Error in chol2inv(object$m$Rmat()) : l'elemento (3, 3) ? zero, quindi l'inversa non pu? essere calcolata Which translated should be: Error in chol2inv(object$m$Rmat()): the element (3, 3) is zero (NULL?), that's why the inverse (inverse function?) can not be computed Does somebody have an idea on how to fix this? Thanks Laura
lauramorgana <at> bluewin.ch <lauramorgana <at> bluewin.ch> writes:> > Hello, > I'm using the following for loop to find regression curves using a list offunctions (formList), a list of .. long non-reproducible code removed> And I got the following error message: > Error in chol2inv(object$m$Rmat()) : l'elemento (3, 3) ? zero, quindil'inversa non pu? essere calcolata> Which translated should be: Error in chol2inv(object$m$Rmat()): the element(3, 3) is zero (NULL?),> that's why the > inverse (inverse function?) can not be computednls is rather nasty or nice in telling you when the result should not be trusted. Other software gives nonsense result without blinking. In package nlme, there is a function nlsList which does directly what you want, but there is little help besides revising the model for the cases without convergence. Also try check Gabor Grothendieks package "nls2" which could help you finding better start values. Dieter
Hello Dieter and everyone, Thank you for your advice... but I didn't manage to solve my problem... :-( I actually like the fact that R tells me which ones of my regressions didn't achieve convergence and gives me a warning saying that there was a false or singular convergence... the problem is that out of 35 regressions I do with my loop, only 5 don't achieve convergence and I would like to be able to get the summaries(or sigma, or coef, ...) of the 30 regressions that did achieve convergence... (I know from the start that some regression functions will work for some variable and not necessarily for others) At the moment I check which ones reach convergence by doing print(resultList) and then I extract the summary by doing the following loop: summaryList<-list() for (i in c(1:8, 11:14, 16:24, 26:34)) { summaryList[[i]]<-summary(resultList[[i]]) } But this is quite tedious, since I will have to repeat it for other rivers and also in the next years... Is there a way to tell R to show me the summary of all the results anyway? Cause right now if I do: summaryList<-list() for (i in length(resultList)) { summaryList[[i]]<-summary(resultList[[i]]) } R only shows me the first 8 summaries and then stops because the ninth didn't reach convergence... Any suggestion? P.S. I tried to use nls2 but I have the same problems... lauramorgana <at> bluewin.ch <lauramorgana <at> bluewin.ch> writes:> > Hello, > I'm using the following for loop to find regression curves using a list offunctions (formList), a list of .. long non-reproducible code removed> And I got the following error message: > Error in chol2inv(object$m$Rmat()) : l'elemento (3, 3) ? zero, quindil'inversa non pu? essere calcolata> Which translated should be: Error in chol2inv(object$m$Rmat()): the element(3, 3) is zero (NULL?),> that's why the > inverse (inverse function?) can not be computednls is rather nasty or nice in telling you when the result should not be trusted. Other software gives nonsense result without blinking. In package nlme, there is a function nlsList which does directly what you want, but there is little help besides revising the model for the cases without convergence. Also try check Gabor Grothendieks package "nls2" which could help you finding better start values. Dieter ______________________________________________ R-help at 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.
Thank you a lot!!! That was fantastic! It worked perfectly!!! Laura Hi Laura, try using the functions try() and inherits() to "catch" any errors in the loop: summaryList <- list() for (i in 1:35) { tempSummary <- try(summary(resultList[[i]]), silent = TRUE) if (inherits(tempSummary, "try-error")) { summaryList[[i]] <- NA } else { summaryList[[i]] <- tempSummary } } I hope you can make it work?! :-) Christian