I'm just getting started in R, got my feet wet with a few linear regression problems where I had samples of the dependent and independent variables. I'd now like to tackle a different problem and not sure how to go about it.
x is known to be between 1 to 100
There are a series of simple linear equations for different values
of x:
f(12) = f(15) + f(45)
f(22) = f(30) + f(31)
f(49) = f(55) + f(98)
f(71) = f(72) + f(100)
f(85) = f(99) + f(100)
We can also set f(1) = 100 and f(1) > f(2) > f(3) > ... > f(100) > 0
There is not an f(x) that solves all of these equations, but I would like to model an f(x) that comes closest to approximating based on the sample equations.
I believe the best route for this is a least squares estimation. In order to do this in R, I believe I need to set this up as a matrix set up with equalities and inequalities, where:
x1 = 100
-x12 + x15 + x45 = 0
-x22 + x30 + x31 = 0
-x49 + x55 + x98 = 0
-x71 + x72 + x100 = 0
-x85 + x99 + x100 = 0
In order to do this, I have been referencing the limSolve documentation. If I try to use the limSolve package, utilizing lsei, I would set the following for the equalities:
E <- matrix(ncol = 100, nrow = 6, byrow=TRUE, data=c(1,0...,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,1,...1,...))
F <- c(100,0,0,0,0,0)
For the inequalities, we can write the following:
x1 - x2 > 0
x2 - x3 > 0
...
x99 - x100 > 0
x100 > 0
And set these to G & H
G <- matrix(ncol=100,nrow=100,byrow=TRUE,data=c(1,-1,0,...,1))
H <- rep(0,100)
I believe at that point I should be able to run
lsei(E,F,G,H)$X
to model for X from x1 to x100.
When I do this, I get "No equalities - setting type = 2". If I run lsei as:
lsei(E,F,G,H,A=diag(nrow=100),B=rep(0,100))$X
I get an array x1..x100 of 0's, which doesn't satisfy the inequalities I defined.
Would appreciate any advice on what I might be doing wrong to run this approximation. Not entirely convinced I'm down the right path to best approximate x1..x100, so definitely welcome any advice.