I have the model that I need to estimate, $$ Y = \pi_0 + \pi_1 X_1 + \pi_2 X_2 + \pi_3 X_3 + \varepsilon, $$ with $\sum_k \pi_k = 1 \text{ for }k \geq 1$ and $\pi_k\ge0 \text{ for }k \geq 1$.
Elvis answer to another question solves this for the case of $\pi_0 = 0$. Here's his/her code of this solution:
> library("quadprog");
> X <- matrix(runif(300), ncol=3)
> Y <- X %*% c(0.2,0.3,0.5) + rnorm(100, sd=0.2)
> Rinv <- solve(chol(t(X) %*% X));
> C <- cbind(rep(1,3), diag(3))
> b <- c(1,rep(0,3))
> d <- t(Y) %*% X
> solve.QP(Dmat = Rinv, factorized = TRUE, dvec = d, Amat = C, bvec = b, meq = 1)
$solution
[1] 0.2049587 0.3098867 0.4851546
$value
[1] -16.0402
$unconstrained.solution
[1] 0.2295507 0.3217405 0.5002459
$iterations
[1] 2 0
$Lagrangian
[1] 1.454517 0.000000 0.000000 0.000000
$iact
[1] 1
How can I adjust this code such that it can estimate an intercept?
This has been cross-posted here because my group in my assignment is getting annoyed that I haven't estimated this regression yet. I will answer this question here if/when the other forum participants get there first.