Lorenzo Isella
2012-Jan-18 13:25 UTC
[R] Non-linear Least Square Optimization -- Function of two variables.
Dear All,
In the past I have often used minpack (http://bit.ly/zXVls3) relying
on the Levenberg-Marquardt algorithm to perform non-linear fittings.
However, I have always dealt with a function of a single variable.
Is there any difference if the function depends on two variables?
To fix the ideas, please consider the function
f(R,N)=(a/(log(2*N))+b)*R+c*N^d,
where a,b,c,d are fit parameters.
For a set of values {N_i, R_i}, i=1,2,.....etc... can I use minpack as
for the case of function of a single variable?
Should I instead resort to another package?
Any suggestion is welcome.
Many thanks
Lorenzo
Berend Hasselman
2012-Jan-18 15:11 UTC
[R] Non-linear Least Square Optimization -- Function of two variables.
On 18-01-2012, at 14:25, Lorenzo Isella wrote:> Dear All, > In the past I have often used minpack (http://bit.ly/zXVls3) relying > on the Levenberg-Marquardt algorithm to perform non-linear fittings. > However, I have always dealt with a function of a single variable. > Is there any difference if the function depends on two variables? > To fix the ideas, please consider the function > > f(R,N)=(a/(log(2*N))+b)*R+c*N^d, > > where a,b,c,d are fit parameters. > For a set of values {N_i, R_i}, i=1,2,.....etc... can I use minpack as > for the case of function of a single variable?Yes.> Should I instead resort to another package?No necessarily. Here is an example fRN <- function(par,R,N,Y) { a <- par[1] b <- par[2] c <- par[3] d <- par[4] res <- Y - ((a/(log(2*N))+b)*R+c*N^d) } set.seed(1) T <- 50 R <- runif(T) N <- 4+runif(T) a <- 1 b <- 2 c <- .5 d <- .7 u <- rnorm(T)/5 sum(u^2) Y <- (a/(log(2*N))+b)*R+c*N^d + u plot(Y) library(minpack.lm) par.start <- c(1,1,.2,.3) nls.lm.control(maxiter=100) nls.lm(par.start, fRN, R=R, N=N, Y=Y) Berend
Reasonably Related Threads
- Confindence interval for Levenberg-Marquardt fit
- Matlab's lsqnonlin
- How is the Gauss-Newton method compared to Levenberg-Marquardt for curve-fitting?
- R interface for MINPACK least squares optimization library
- R interface for MINPACK least squares optimization library