Solving nonnegative linear system in R - r

Is it possible to find a solution to the undetermined system Ax = b, x >= 0 using some native R function? I can certainly write a linear program and use lpsolve, but am hoping for something native.

Actually, I found what I was looking for. The package nnls addresses exactly my problem.

Related

R linprog delivers incorrect solution

I am solving the following simple linear program with pracma::linprog in R:
library(pracma)
cc=c(1)
A=as.matrix(-1)
b=c(1)
linprog(cc,A,b,maximize=FALSE)
The solution returned is x=0.
However, this solution is incorrect: a lower value of the linear program can clearly be obtained at x=-1.
I find that both Wolfram Alpha and Matlab return the correct solution.
Why does linprog return the wrong solution? Is there any way to correct this problem?
From ?linprog
This is a first version that will be unstable at times. For real
linear programming problems use package lpSolve
Which gives the same answer
lpSolve::lp(direction='min', cc,A,"<=",b)
Success: the objective function is 0
And from ?lp
Note that every variable is assumed to be >= 0!

How to use `cplexAPI` to solve quadratic programs/linear programs with quadratic constraints?

I am trying to use cplexAPI to solve quadratic programs or linear programs with a quadratic constraint.
While it seems to be pretty straightforward to use cplexAPI to solve linear programs (with the vignette at https://cran.r-project.org/web/packages/cplexAPI/vignettes/cplexAPI.pdf), it seems that using cplexAPI to solve quadratic programs or linear programs with a quadratic constraint is much more difficult. I tried to look over the package documentation, but I have no clue on how to do so.
Therefore, may I know how to use cplexAPI to solve quadratic programs or linear programs, or if there is any code samples for these two tasks?
In addition, the package Rcplex seems to be pretty similar, but its last update is already more than 5 years ago. So it would be really nice to know how the above two tasks can be done using cplexAPI in R. Thanks!
with cplexAPI you may use addQConstrCPLEX to add quadratic constraints

Mathematical constrained optimization in R

I have a mathematical optimization which I wish to solve in R consider this system/problem:
How Can I solve this problem in R?
In this model Budget, p_l for all l and mu_target are fixed constants while muis a given m-dimensional vector and R is a given n by m matrix.
I have looked into constrOptim and lp but I don't have the imagination to implement the constraints
Those functions require that I have a "constraint" matrix but my problem is that I simply don't know how to design that constraint matrix. There are not many examples with decision variables on both sides of the equations.
Have a look on the nloptr package. It has quite extensive documentation with examples. Lots of algorithms to choose from, depending what problem you are trying to resolve.
NLoptr link

Calculate D-efficiency of an experimental desgin in R

I have an experimental design. I want to calculate its D-efficiency.
I thought R package AlgDesign could help. I found function optFederov which generates the design and - if the user wants - returns its D efficiency. However, I don't want to use optFederov to generate the design - I already have my design!
I tried eval.design(~.,mydesign). But the only metrics it gives me are: determinant, A, diagonality, and gmean.variances. Maybe there is a way to get from determinant or A to D-efficiency (I am not a mathematician, so I am not sure). Or maybe some other way to calculate D-efficiency "manually" so to say?
Thanks a lot for any hint!
I was working on a similar project. I found out this formula Deff = (|X'X|^(1/p))/ND in this link. Where X is the model matrix, p is the number of betas in you linear model and ND the number of runs your experiment has. You could just make a code like this and it will do the trick.
det(t(X)%*%X)^(1/beta)/(numRuns)
I tested the results using JMP for my project so I believe this is the correct formula
Determinant, the first result given by eval.design, is the D-efficiency.

Solution to overdetermined systems

How to find solution to overdetermined systems in Macsyma, Scilab, Octave?
You don't say what type of system it is. If it is non-linear, you are in a very serious mess. In the linear case, You are trying to solve the system Ax = y, where A is not invertible. Even though it is not invertible, it admits a pseudo inverse, which you can stably compute using SVD.
The backslash operator gives the least-squares solution in Scilab.

Resources