[R] nls() lower/upper bound specification
Stephen Tucker
brown_emu at yahoo.com
Thu Jul 5 01:16:40 CEST 2007
Dear all,
In optim() all parameters of a function to be adjusted is stored in a single
vector, with lower/upper bounds can be specified by a vector of the same
length.
In nls(), is it true that if I want to specify lower/upper bounds, functions
must be re-written so that each parameter is contained in a single-valued
vector?
## data input
x <- 1:10
y <- 3*x+4*x^2+rnorm(10,250)
## this one does not work
f <- function(x)
function(beta)
beta[1]+ beta[2]*x+beta[3]*x^2
out <- nls(y~f(x)(beta),data=data.frame(x,y),
alg="port",
start=list(beta=1:3),
lower=list(beta=rep(0,3)))
(However, this works if I do not specify a lower bound)
## this one works
g <- function(x)
function(beta1,beta2,beta3)
beta1+ beta2*x+beta3*x^2
out <- nls(y~g(x)(beta1,beta2,beta3),data=data.frame(x,y),
alg="port",
start=list(beta1=1,beta2=1,beta3=1),
lower=list(beta1=1,beta2=1,beta3=1))
Thanks in advance!
Stephen
More information about the R-help
mailing list