[R-sig-eco] starting values for cubic splines using nls
bergeraa at msu.edu
bergeraa at msu.edu
Thu Nov 24 00:20:31 CET 2011
R-sig-eco?ers:
I?m trying to fit a model of length at age in a von Bertalanffy or
another growth function, but with longitude as a covariate that
modifies both K and Linf.
So in the vonB, length = Linf * (1-exp(-K*(age - Tzero)))
but with longitude in the model this becomes:
length = f(longitude) * Linf * (1-exp(- g(longitude) * K*(age - Tzero)))
I can fit the model above with f() and g() as polynomials, but it
would be much better to have f() and g() as cubic splines. Close to
the boundaries, the polynomials (quadratics or cubics) go to values
that aren't credible.
However, I?m having trouble specifying starting values. Does anyone
have a solution?
Below is a simple example of what I?m trying to do.....
# set up the data
age<- 1:100
alpha<- runif(100)
length<- (1 + 2*alpha + 2*alpha^2) * age + rnorm(100)/5
# the models
nls(length ~ (par0 + par1* alpha + par2* alpha ^2) * age,
start=c(par0=0,par1=0,par2=0)) # polynomial version - this works
nls(length ~ ns(alpha,df=3) * age, start=list(parname=ns(1:100,df=3)))
# cubic spline version - this doesn't work
Thanks much,
Aaron Berger
Please update my contact information as follows:
Aaron Berger, Fisheries Scientist
Stock Assessment and Modelling Section
Secretariat of the Pacific Community, BP D5, 98848 Noumea CEDEX, New Caledonia
(+687) 262000 ext. 31328
aaronb at spc.int
More information about the R-sig-ecology
mailing list