Solved – Specifying parameter constraints in nls()

Is it possible to specify that one parameter must be larger than another parameter in an nls call in my R script?

Here's my nls call:

fit <- nls(y ~ ifelse(g, m1 * (x - x0) + y0, m2 * (x - x0) + y0),             start = c(m1 = -1, m2 = 1, y0 = 0, x0 = split),             algorithm = "port",             lower = c(m1 = -Inf, m2 = -Inf, y0 = -Inf, x0 = split),             upper = c(m1 = Inf, m2 = Inf, y0 = Inf, x0 = (split+1)),             data=data.frame(x,y)) 

It is finding values for the parameters m1, m2, x0, and y0. But I want to require that m2 must be LARGER than m1. How can I do this?

No.

However it seems you are using nls in a wrong way — it will never work with non-differentiable functions. Can't you just fit two linear models to both parts of the data (i.e. data.frame(x,y)[g,] and data.frame(x,y)[!g,])?

Similar Posts:

Rate this post

Leave a Comment