Dear all, I already asked about to run a constrained regression like y=b0 + b1X1+b2x2+b3x3, with constraints: b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the performance Analytic packages. However the style.QPfit function does not estimate an intercept. As i really can not extend this function for my problem, I noticed pcls. Pcls is maybe an alternative for my problem. Can somebody help me to implement the constraints in pcls. Maybe it can be done by designing a designed matrix X with extra column for the inercept (b0) and to force C in a way. But how I do not know. Your help is greatly appreciated Philipp -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html Sent from the Rmetrics mailing list archive at Nabble.com.
Constrained Regression with Intercept in pcls
6 messages · Philipp, Enrico Schumann, thomas.chan.sf at boci-pru.com.hk
Hi Philipp, you should be able to solve this with package quadprog/solve.QP. require(quadprog) p <- 3 ## number of regressors T <- 100 ## number of obs X <- array(rnorm(T*p), dim = c(T,p)) X <- cbind(1,X) ## add a constant y <- rnorm(T) ## variant 1 -- linear regression coef(lm(y ~ -1 + X)) ## variant 2 -- quadprog (should be the same as variant 1) Dmat <- crossprod(X) dvec <- as.vector(t(as.matrix(y)) %*% X) Amat <- as.matrix(rep(0, p+1)) solve.QP(Dmat = Dmat, dvec = dvec, Amat = Amat)$solution ## variant 3 -- quadprog, now with restrictions bvec <- c(1, rep(0, p)) Amat <- rbind(1,diag(p)) Amat <- cbind(0, Amat) w <- solve.QP(Dmat = Dmat, dvec = dvec, Amat = t(Amat), bvec=bvec, meq=1)$solution w ## result sum(w[-1]) ## check constraint see also here http://comisef.wikidot.com/tutorial:minimisevariance regards, Enrico Am 01.12.2011 17:18, schrieb Philipp:
Dear all, I already asked about to run a constrained regression like y=b0 + b1X1+b2x2+b3x3, with constraints: b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the performance Analytic packages. However the style.QPfit function does not estimate an intercept. As i really can not extend this function for my problem, I noticed pcls. Pcls is maybe an alternative for my problem. Can somebody help me to implement the constraints in pcls. Maybe it can be done by designing a designed matrix X with extra column for the inercept (b0) and to force C in a way. But how I do not know. Your help is greatly appreciated Philipp -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html Sent from the Rmetrics mailing list archive at Nabble.com.
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Enrico Schumann Lucerne, Switzerland http://nmof.net/
Alternatively, the lsei (least squares with equalities and inequalities) fu nction in the limSolve package solves for the least square solution to a system of equations with linear and nonlinear constraints. |------------> | From: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |Philipp <jasonhome at freenet.de> | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | To: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |r-sig-finance at r-project.org | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | Date: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |02/12/2011 00:20 | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | Subject: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |[R-SIG-Finance] Constrained Regression with Intercept in pcls | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | Sent by: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |r-sig-finance-bounces at r-project.org | >----------------------------------------------------------------------------------------------------------------------------------------| Dear all, I already asked about to run a constrained regression like y=b0 + b1X1+b2x2+b3x3, with constraints: b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the performance Analytic packages. However the style.QPfit function does not estimate an intercept. As i really can not extend this function for my problem, I noticed pcls. Pcls is maybe an alternative for my problem. Can somebody help me to implement the constraints in pcls. Maybe it can be done by designing a designed matrix X with extra column for the inercept (b0) and to force C in a way. But how I do not know. Your help is greatly appreciated Philipp -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html Sent from the Rmetrics mailing list archive at Nabble.com. _______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ______________________________________________________________________ This email has been scanned by the Symantec Email Security.cloud service. For more information please visit http://www.symanteccloud.com ______________________________________________________________________ --------------------------------------------------------------------------------------- Important : The information contained in this e-mail and any attachment thereof is intended only for use of the addressee and is confidential and may be privileged and/or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, copying, dissemination or any other action taken or omitted to be taken in reliance upon this information is strictly prohibited. If you have received this communication in error, please notify the sender immediately by reply and delete this message from your system. Any views expressed in this e-mail are those of the individual sender except where the e-mail states otherwise and the sender is authorized to state them to be the views of BOCI-Prudential Asset Management Limited. Unless otherwise stated, any information given in this e-mail shall not be regarded as an offer, solicitation, invitation, advice or recommendation to buy or sell any investment or securities within or outside Hong Kong SAR. Any reference to the terms of executed transactions should be treated as preliminary only and subject to our formal written confirmation. ______________________________________________________________________ This email has been scanned by the Symantec Email Security.cloud service. For more information please visit http://www.symanteccloud.com
3 days later
Hi Enrico, Thanks for your answer. I tried the third alternative, which I need with my two constraints. But I get the error message: Amat and dvec are incompatible! Can you help me again? Regards Phillip -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4161066.html Sent from the Rmetrics mailing list archive at Nabble.com.
Hi Enrico, sorry everything back. I got a manuel mistake.Your code works. Now I try to form it for my data. I hope it works. regards Phil. -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4161890.html Sent from the Rmetrics mailing list archive at Nabble.com.
10 days later
Thank You Enrico, Your message was very helpful. I could implement everything and I could also extend the function for my problem. thank you for that regards Philipp -- View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4205163.html Sent from the Rmetrics mailing list archive at Nabble.com.