# Weighted average of models optimization

Hello to everyone. I am trying to replicate a simple optimization that I did in microsof excel in R. I have some timeseries of certain models and I want to find the multipliers (i,j,k,l) that minimise the sum of squared residuals of the average model to the observed values (temps\$baltic_45_65_may). For some reason, the outcome violates the constraints I have put. I am completely new to this and not very proficient in R so excuse me if I didn’t formulate the question correctly.

res <- function(i,j,k,l){
res = sum(((itemps\$nemo_45_65_may_box2+
j
temps\$mom_45_65_may_box2+
ktemps\$getm_clml11_45_65_may_box2+
l
temps\$getm_uerral03_45_65_may_box2)-temps\$baltic_45_65_may)^2)
}

library(CVXR)

i <- Variable(1)
j <- Variable(1)
k <- Variable(1)
l <- Variable(1)

# objective

objective <- Minimize(res(i,j,k,l))

# define problem

constraint1 <- i+j+k+l == 1
constraint2 <- i >= 0
constraint3 <- j >= 0
constraint4 <- k >= 0
constraint5 <- l >= 0

problem <- Problem(objective, constraints = list(constraint1, constraint2, constraint3, constraint4, constraint5))

# solve problem

result <- solve(problem)

# results

result\$getValue(i) # optimal x
result\$getValue(j)
result\$getValue(k)
result\$getValue(l)

Despite being located at cvxr.com , the CVX forum does not address CVXR (which it predates), and only addresses CVX and TFOCS.

So your request for help on CVXR is off-topic here. Perhaps you can ask at https://stackoverflow.com/questions/ask and use the `cvxr` tag. I don’t know whether there is a better support forum for CVXR.

I can give you these generic tips: Look at the solver log and see what it reports. Look at the solution status reported by CVXR. Also, even if CVXR and the solver claim that the problem has been solved to optimality, the solver, and therefore CVXR, allow constraint violations by less than some tolerance (such as 1e-8).

Thank you very much for your instant reply! It seems that the violations are very low in my case, so I think it is the optimal solution. As far as the relevance of the topic is concerned, would you like me to delete the topic?

If this were Vietnamese gaming SPAM, I would have deleted it. Your posting on this forum is a very understandable mistake. The actual substance of your “issue” is pertinent to CVX as well as CVXR.