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?