[R] Test model for singular gradient matrix
dmhultst
dmhultst at lamar.colostate.edu
Fri Oct 16 17:49:09 CEST 2009
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/
More information about the R-help
mailing list