Hello, I am working with a real-time hydrologic modeling system, and I am using R (R batch script on Linux) to create a non-linear relationship (exponential) between observed data. I want to extract the non-linear coefficients (“b” and “m”) if the relationship can be created, if the relationship cannot be created I will use default “b” and “m” coefficients. I keep getting an error of singular gradient matrix (see below). I want to test whether I can create the relationship (because if I cannot the script crashes) and use the model extracted coefficients or use default coefficients.
Model in R batch script: fit.nls <- nls(P~(b*exp(m*Z)), start=list(m=0.015,b=0.017), control=list(maxiter=200)) Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates ** the initial parameter values are also the default Question: 1) Is there a way to test fit.nls (or the data) prior to see if this error occurs. 2) Would this test be set up as an if statement? if (fit is good) {proceed model coefficients} else {use default coefficients}? Thanks for all your help, Doug *************************************** Douglas M. Hultstrand Ph.D. Candidate Earth Sciences Watershed Science Program Colorado State University http://www.cnr.colostate.edu/~dmhultst/ ______________________________________________ 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.