[R] Syntax for nls optimization function

HC hcatbr at yahoo.co.in
Fri Jun 15 05:49:51 CEST 2012


I am working on minimization of sum of squared errors for a problem that has
2 box-constrained parameters.

I got the solution for this problem using "L-BFGS-B" method in optim
function using an R code as

res<-optim(par=c(parInit), fn=myFunction, method = c("L-BFGS-B"), lower =
parMin, upper = parMax,
                                             
control=list(trace=3,factr=iFactr,maxit=300),                                                        
                                             
parOpt=parOpt,parVal=parVal,objFun=iObjFun,dset=dHM1,whatPDM=whatPDMi)

Here "myFunction" is a function that provides the value of the sum of
squared error that is computed after a lot of computations. There are other
parameters and data (through a dataframe dHM1) that are supplied to
"myFunction" as given in last line of the above R code.

Since the optim function takes very long (about 40 minutes) to converge, I
am thinking I can use (a  simpler) *nls function* instead as the objective
function is a well behaved sum of squared error function only.

However, my problem is that *nls function uses a "formula" instead of the
function fn in* as in optim and I am not able to know how to pass everything
to that formula (that is in a function form) that I could in optim. I tried
many things around it as below:

res<nls(~myFunction(x),  start=list(x=c(parInit)), algorithm=c("port"), 
                                                            trace=TRUE,
model=TRUE, lower = parMin, upper = parMax, 
                                                            parOpt=parOpt,
parVal=parVal, objFun=iObjFun, dset=dHM1, whatPDM=whatPDMi)

Note:  ~ it is a tilda in the above code.

I know that I am not providing the correct syntax for "formula" in nls
function. I get error messages, e.g.,
Error in x$formula : object of type 'closure' is not subsettable

Could somebody point me to the correct syntax for this nls application,
particularly for the syntax for the formula.

Thank you.
HC





--
View this message in context: http://r.789695.n4.nabble.com/Syntax-for-nls-optimization-function-tp4633451.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list