rnlslevenberg-marquardt

Apply penalty function to non-linear least square estimation convergence with bounds in R - package minpack.lm


I want to perform a non-linear least square estimation using the function nlsLM from the package minpack.lm.

I want to impose an upper and a lower bound to the estimation to force the algorithm to find the solution within a specific support.

Something along these lines:

library(minpack.lm)
mydata <- data.frame(x=c(0,5,9,13,17,20),y = c(0,11,20,29,38,45))
myfit <- nlsLM(formula(y ~ a*x), data = mydata, start=list(a = 2.5), lower = c(a = 0), upper = c(a = 5))
summary(myfit)

My question is:

is it possible to apply a penalty function to nlsLM, so to avoid that the algorithm returns a corner solution? e.g. in my example a is not equal to 0 or 5.

Caveats: I am exclusively looking at a solution with the package minpack.lm.


Solution

  • To implement this barrier function which approaches infinity as a approaches 0 from the right or 5 from the left:

    log(a)^2 + log(5-a)^2 
    

    as a penalty we form the objective function

    (y[1] - a*x[1])^2 + ... + (y[n] - a*x[n])^2 + (0 - log(a))^2 + (0 - log(5-a))^2
    

    like this

    n <- nrow(mydata)
    mydata0 <- rbind(mydata, 0 * mydata[1:2, ])
    nlsLM(y ~ c(a * x[1:n], log(a), log(5 - a)), mydata0, start = list(a = 1))