optimization - Finding Contraints Matrix in constrOptim (R) -
i set constraints constroptim
optimize following function:
logistic<-function(b,x,target){ b1<-b[1] b2<-b[2] log<-function(x){1/(1+exp(-(b1+b2*x)))} abs(mean(log(x))-target) }
optimization target=.75
can done using
optim(c(1,1),logistic,x=data,target=.75,hessian=true,method='sann')
method sann seems necessary, function not differentiable.
the constraint b2>0 (condition 1) or b2<0 (condition 2), while b1 can real number. how can extend function constroptim
? specifically, not know how specify arguments ui
, ci
.
alternative approaches optimization under these constraints welcome. thanks.
edit think found workarround. find constraint b2<0 redefining logistic
to
logistic_lt<-function(b,x,target){ b1<-b[1] b2<-b[2] if(b2>0){b2<-b2*(-1)} log<-function(x){1/(1+exp(-(b1+b2*x)))} abs(mean(log(x))-target) }
still i'd interested in solution involving constroptim.
Comments
Post a Comment