Solving quadratic optimization problems with complex constraints in R -


does know how implement regression in r our goal minimize sum of squares of residuals subject residuals being non-negative , constraints on coefficients? asking univariate regression quadratic term b_0 <=0, b_1>=0 , b_2>=0.

i able solve similar problem goal minimize sum of residuals using lpsolve package. solving sum of squares seems considerably harder in r. ideas?

question asked on cross validated too:

https://stats.stackexchange.com/questions/272234/restrictions-on-residuals-and-coefficients-in-regression-dfa

here code fragment tries implement solution given above:

library(quadprog)  xvec <- c(8.1,6.4,6.8,13.3,0.7,2.4,3.5,6.5,1.9,2.8,8.0,6.8,4.6,18.6,1.1,9.5,1.4,3.8,0.7,11.5,7.1,8.2,7.0,7.0,2.2,9.8,0.3,2.5,10.6,1.4,31.0) yvec <- c(15.8,10.6,12.8,26.5,1.3,3.9,6.2,13.1,3.1,4.4,12.6,11.6,9.3,35.3,1.8,16.0,2.7,6.4,1.3,18.9,12.0,14.3,13.5,11.3,3.5,16.0,0.6,4.8,17.7,2.5,71.0)  k <- length(xvec)  # decision vars: c(beta0, beta1, beta2, r1, ..., rk)  amat <- cbind(rep(1,k), xvec, xvec^2, diag(rep(1, k))) amat <- rbind(amat, c(-1, rep(0,k+2)), c(0,1, rep(0,k+1)), c(0,0,1, rep(0,k)))  bvec <- c(yvec, rep(0,3))  dmat <- diag(rep(1, k+3)) dmat[1:3, 1:3] <- diag(rep(0.000001, 3))  s <- solve.qp(dmat=dmat, dvec=rep(0, k+3), amat=t(amat), bvec=bvec, meq=k)  s$solution 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -