[R] Lower bounds on selfStart function not working

Schatzi adele_thompson at cargill.com
Mon Nov 7 16:29:58 CET 2011


I adapted a selfStart function and the lower bounds are not working. The
parameter "b" is negative, whereas I would like the lower bound to be zero.
Any ideas? Thanks.

Here is my code (I am still figuring out how to easily make replicable
examples):
A<-1.75
mu<-.2
l<-2
b<-0
x<-seq(0,18,.25)
create.y<-function(x){
y<-b+A/(1+exp(4*mu/A*(l-x)+2))
return(y)
}
ys<-create.y(x)
yvec<-(rep(ys,5))*(.95+runif(length(x)*5)/10)
Trt<-factor(c(rep("A1",length(x)),rep("A2",length(x)),rep("A3",length(x)),rep("A4",length(x)),rep("A5",length(x))))
Data<-data.frame(Trt,rep(x,5),yvec)
names(Data)<-c("Trt","x","y")

NewData<-groupedData(y~x|Trt,data=Data)

powrDpltInit <-
function(mCall, LHS, data) {
   xy     <- sortedXyData(mCall[["x"]],LHS,data)
   A.s  <- max(xy$y)-min(xy$y)
   mu.s  <- A.s/7.5
   l.s <- 0
   b.s    <- max(min(xy$y),0.00001)
   value  <- c(A.s, l.s, mu.s, b.s)

#function to optimize
func1 <- function(value) {
   A.s  <- value[1]
   mu.s  <- value[2]
   l.s <- value[3]
   b.s    <- value[4]
  y1<-rep(0,length(xy$x)) # generate vector for predicted y (y1) to evaluate
against observed y
  for(cnt in 1:length(xy$x)){
  y1[cnt]<- b.s+A.s/(1+exp(4*mu.s/A.s*(l.s-x[cnt])+2))}  #predicting y1 for
values of y
  evl<-sum((xy$y-y1)^2) #sum of squares is function to minimize
  return(evl)}

#optimizing
oppar<-optim(c(A.s , mu.s , l.s , b.s),func1,method="L-BFGS-B",
lower=c(0.0001,0.0,0.0,0.0),
control=list(maxit=2000,trace=TRUE))

#saving optimized parameters
value<-c(oppar$par[1L],oppar$par[2L],oppar$par[3L],oppar$par[4L])

   names(value) <- mCall[c("A","mu","l","b")]
   value

}

SSpowrDplt<-selfStart(~b+A/(1+exp(4*mu/A*(l-x)+2)),initial=powrDpltInit,
parameters=c("A","mu","l","b"))

test1<-nlsList(SSpowrDplt,NewData)
coef(test1)

-----
In theory, practice and theory are the same. In practice, they are not - Albert Einstein
--
View this message in context: http://r.789695.n4.nabble.com/Lower-bounds-on-selfStart-function-not-working-tp3999231p3999231.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list