fishR-Core-Team / FSA

FSA (Fisheries Stock Assessment) package provides R functions to conduct typical introductory fisheries analyses.
https://fishr-core-team.github.io/FSA/
GNU General Public License v2.0
65 stars 20 forks source link

Trouble with fitting von Bertalanffy curve to a small data set #110

Closed diogoprov closed 2 months ago

diogoprov commented 3 months ago

Hi, I'm trying to fit a von Bertalanffy curve to a relatively small data set. It has

dim(frog_data)
[1] 28  3

I'm following your tutorial:

# Define von Bertalanffy growth function
vbmod <- svl ~ Linf * (1 - exp(-K * (age - t0)))

starts <- vbStarts(formula = svl ~ age, meth0 = "poly", data = frog_data)

mymod <- nls(vbmod, data = frog_data, start = starts)

Error in nls(vbmod, data = frog_data, start = starts) : 
  number of iterations exceeded maximum of 50

but then I got an error in the nls function. The vbStarts was also returning an error, but changing the meth0 solved it.

There's relatively little variation in age. This is for frogs.

Captura de Tela 2024-06-19 às 17 05 42

Any ideas?

Thank you

droglenc commented 3 months ago

Thanks for the note. This is a common problem with a) sparse data sets; b) data sets that don't follow the general von B curve shape (e.g., no obvious asymptote); c) data sets with few young fish (so hard to define t0); few old fish (so no obvious asymptote and thus hard to define Linf), or both; d) data sets with lots of variability in length-at-age (i.e., fish of the same age have very variable lengths; e) poor starting values; or f) something else.

It is difficult to provide a more specific answer without your data. I would suggest using plot=TRUE in your vbStarts() code so that you can "see" how your data fits the vonB model with your starting values. This plot will also provide some insight into whether your data will look like they might follow a vonB model.

Depending on what this plot looks like you might a) realize that a von B is not appropriate for your data, b) your data is inadequate to fit the model, c) you should use better starting values, d) you should increase the number of iterations or the tolerance in nls() (see ?nls.control), e) you should use a different fitting algorithm, f) you should not try to fit a model and just report the mean lengths-at-age, or g) something else.

After all of that, I suspect you simply have a data problem (i.e., you basically only have 3 ages of frogs ... ages 4-7 are represented by only one fish each).

Hope that this helps some. Good luck with your project.

p.s., I am away for the next week or so, and won't, if you reply, be able to respond during that time.

diogoprov commented 3 months ago

Indeed, we don't have enough data points in some ages. The model line doesn't seem to pass through most of the points when I shoose 'typical' and consequently gives poor starting values:

Captura de Tela 2024-06-20 às 11 12 16

but then, even if I change to other param , like:

starts <- vbStarts(formula = svl ~ age, data = frog_data, plot = TRUE, param = "vonBertalanffy")

it draws a straight line with not clear starting age. So the problem seems not to be the asymptote, but with the uncertainty/wide variation in length for young frogs...

Captura de Tela 2024-06-20 às 11 10 43

We'll try to perhaps add more data as we go along and see what happens.

Thank you very, very much for your quick - enlightening - response.

All the best, Diogo