Until recently, my R usage was limited to plotting with ggplot etc. At the moment, I'm trying to solve linear problems with R using lpSolve, which proves to be quite the challenge. I'm trying to achieve similar results as I got with the Solver in MS Excel.
What I've got:
A: a 20x6 matrix with observations.
> head(Filtered)
C1 C2 C3 C4 C5 C6
1 15.6 17.6 12.0 12.0 27.8 15.0
2 20.0 18.2 10.7 9.3 17.8 24.0
3 20.5 19.5 11.3 10.8 17.2 20.7
4 21.3 20.9 11.6 10.5 19.7 15.9
5 26.7 28.7 14.9 10.2 8.9 10.5
6 25.5 28.1 14.7 9.9 9.9 11.9
B: a 20x1 vector with observations.
> measSSA
[1] 19.4 29.3 29.5 33.9 51.0 45.0 30.8 39.9 31.3 41.3 33.1 32.6 36.9 35.6 41.3 27.7 35.0 27.8 34.6 13.4
c: a 6x1 vector with constrained decision variables
> c
[1] 0.95 2.79 3.91 5.74 5.29 5.64
d: a 6x1 vector with constrained decision variables
> d
[1] 0.0022 4.0000 10.7000 21.1000 44.5000 70.6000
I then calculate simulated values for each element in B based on the corresponding row in A and vectors c and d.
Constant = 0.00377
Result = t(t((Constant*A)%*%diag(c))/d)
Simulated = rowSums(Result)
What I then want to do is minimize the mean square error between B and the simulated vector, which would give me the optimal fit.
MSE = sum((B-Simulated)^2)/20
What I would like to do with lpSolve is vary the values of the vectors c and d to minimize the MSE. However, although I am able to put in vectors c and d as constraining variables with lpSolve, I am not able to set MSE as the minimization objective. How would I go about doing this?
Thanks!