I am looking into fitting a so-called double von Bertalanffy function to fish length-at-age data. Attempting to simplify the situation, the model looks like this ...
Y ~ f(X; a,b,c) if x < Z Y ~ g(X; a,d,e) if x >= Z where * f and g are non-linear functions (the "traditional" "single" von Bertalanffy growth function), * Y (length) and X (age) are observed variables, * a,b,c,d,e are parameters to be estimated, and * Z is not a parameter but is a constant computed from b,c,d,e. I usually fit the "traditional" "single" model with nls() but am unsure of how to fit this model with the "if" statement. I tried search the archives with "piecewise" and either "nls", "nonlinear", or "regression" but did not find anything that seemed to fit this situation. One thought I had was to do something like this (mostly pseudo-code) ... nls(Y~ifelse(X<Z,1,0)*f(X;a,b,c)+ifelse(X>=Z,1,0)*g(X;a,d,e), ...) but am unsure if this makes sense. If anyone can offer some help I would be very appreciative. Thank you in advance. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.