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+
jtemps$mom_45_65_may_box2+
ktemps$getm_clml11_45_65_may_box2+
ltemps$getm_uerral03_45_65_may_box2)-temps$baltic_45_65_may)^2)
}
library(CVXR)
the variable
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)