[R] Singular Gradient Test

Sarah Goslee sarah.goslee at gmail.com
Tue Oct 20 00:12:12 CEST 2009


You could look into try().

Sarah

On Mon, Oct 19, 2009 at 5:49 PM, Douglas M. Hultstrand
<dmhultst at metstat.com> wrote:
> Hello,
>
> I posted this question last week and have not heard anything, I am wondering
> if anyone had ideas for testing a model relationship?
>
> 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. In the R script I some
> times get an error of singular gradient matrix (see below). I want to test
> whether I can create the relationship (singular gradient causes the script
> crash) 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
>
> Specific Questions:
> 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
>


-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list