0

I am trying to produce a von Bertalanffy growth model in R which uses the nls() function, but getting the 'singular gradient' error

The dataset 'FladenA' is in reference to the location where my sample is from, and contains 'maximum height' and 'age' data, which are the two variables that are required for the model

This is the pdf I am using to help produce the model http://derekogle.com/fishR/examples/oldFishRVignettes/VonBertalanffy.pdf

#load in the appropriate packages
library(FSA)
library(FSAdata)
library(nlstools)

#generate reasonable starting values using vbStarts
svTypical <- vbStarts(Max_Height~Age,data=FladenA)

# unlist used only to save space when viewing the results
unlist(svTypical)

#      Linf          K         t0 
#63.1980478  0.1035328  4.5816629 

# creating object that contains a list of the identified starting values
svTypical <- list(Linf=63.1980478,K=0.1035328,t0= 4.5816629)

nls() function requires the growth model expression as the first argument, with the appropriate variable names substituted for the generic length and age variables, the data frame from which to draw the variables in the data= argument, and the list containing starting parameter values in the start= argument. As always, the model fit should be assigned to an object for further analysis.

#Name and input the growth model 
vbTypical <- Max_Height~Linf*(1-exp(-K*(Age-t0)))

# use the nls function with the vbTypical as the growth model expression, dataset for which to draw the variables as Fladen A, and the list containing the starting parameter values as svTypical

fitTypical <- nls(vbTypical,data=FladenA,start=svTypical)

Error in nls(vbTypical, data = FladenA, start = svTypicala) :
singular gradient

This 'singular gradient' is where the issue lies, does anyone know how to explain what this issue is and how I can solve it?

user20650
  • 24,654
  • 5
  • 56
  • 91
JaneEarland
  • 1
  • 1
  • 2
  • The appropriate of these models is hard to judge without seeing the data; this can lead to difficulties in estimation. A quick punt, you you could try getting starting positions using `lm(log(Max_Height) ~ Age)` – user20650 Jan 18 '20 at 01:42
  • Questions to the SO R tag must be reproducible which includes providing the input data in a form that can readily be used in R. As user20650 has mentioned singular gradient can be caused by misspecification of the model or starting values that are too far from the optimum. If the starting values you are using are too far away you could try using the nls2 package to generate better starting values. Base R does provide this as a self starting model already via `SSasympOff` except that the parameters are transformed. Also check out the AR.2 model in the drc package. – G. Grothendieck Jan 19 '20 at 09:45

0 Answers0