r - ContrOptim Function- Error in Argument -
i'm trying replicate excel solver in r- constraint optimization problem
i'm trying minimize cost per action total spend/ total actions equals below function few constraints.
cpa function:
(a+b+c+d)/((consta+(baln(a)))+ (constb+(bbln(b)))+(constc+(bcln(c)))+(constd+(bdln(d)))
where unknown variables a
,b
,c
,d
, const*
stands constant regressions , b*
stand coefficient regression (so values have).
here simplified filled in function i'm trying minimize:
(a+b+c+d)/ (((69.31*ln(a))+(14.885*ln(b))+(21.089*ln(c))+(9.934*ln(d))-(852.93))
constraints:
a+b+c+d>=0 a+b+c+d<=130000(total spend) a<=119000 (maxa) a>=272.56(mina) b<=11000(maxb) b>=2.04(minb) c<=2900(maxc) c>=408.16(minc) d<=136800(maxd) d>=55.02(mind)
i'm doing using constraints optimization function. code below:
g<-function(a,b,c,d) { (a+b+c+d)/((consta+(balog(a)))+ (constb+(bblog(b)))+ (constc+(bclog(c)))+ (constd+(bdlog(d)))) } gb<-function(a) g(a[1], a[2], a[3],a[4]) a<-matrix(c(1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,-1,-1,-1,-1,1,1,1,1),4,10) b<- c(mina, -maxa, minb, -maxb, minc, -maxc, mind, -maxd,-totalspend, 0) constroptim(c(273,6,409,56),g,gb,a,b)
when run optimization function, states wrong arguments (error in ui %*% theta : non-conformable arguments
). think gradient of function coded wrong i'm not sure. appreciated.
Comments
Post a Comment