How can I specify 'starting values' for a cubic spline ns()? I need starting values for all pars when fitting using the nonlinear least squares optimiser nls(). The y variable (length) is a function of 2 variables: alpha and age. The functional form for the age-length relationship is specified as a standard nonlinear growth function, but alpha modifies the age-length relationship in an unknown manner, so I want the flexibility of a cubic spline.
nls() is probably the wrong optimiser to handle this, but can someone suggest a suitable optimiser, and how to specify starting values for the spline? For example (simplifying the real example): x <- 1:100 alpha <- runif(100) y <- (1 + 2*alpha + 2*alpha^2) * x + rnorm(100)/5 nls(y ~ (par0 + par1* alpha + par2* alpha ^2)* x, start=c(par0=0,par1=0,par2=0)) # polynomial version - this works nls(y ~ ns(alpha,df=3)*x,start=list(theta=ns(1:100,df=3))) # cubic spline version - this doesn't work Thanks a lot, Simon ______________________________________________ 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.