Non-negative coefficient restriction in stacked regression I've been reading about stacked regression, as described, for example, here. It seems it's important that when you regress against the first predictors, you require that the regression coefficients are non-negative. How does one do that in R? 
 A: Last night I wanted to solve this problem and thought up a solution. So today I wanted to post it somewhere in case anyone is looking for it. Interesting that you guys suggested the optimization method. That is also what I thought.  Here's the code, it is not great code by any means but should solve people's problems in the future:
install.packages("quadprog")
require(quadprog)

lm.constrained <- function(y, x, Amat, b0){
    x <- cbind(1, x) ## Add coefficient
    D <- t(x) %*% x
    dlittle <- t(x) %*% y
    return(solve.QP(D, dlittle, Amat, b0, 0))
}

So that is all you need. y and x are the same variables that you were using. Amat is basically an identity matrix of dimension your number of variables + 1 for the coefficient, and b0 is the lower limit in your variable.
IF you want to restrict coefficients to non-positive, just enter the negative of the identity. In fact, you can insert positive and negatives.
I test with an example like:
y <- 18:29
x <- cbind(
    c(76.1,77,78.1,78.2,78.8,79.7,79.9,81.1,81.2,81.8,82.8,83.5),
    c(66.1,76,78.1,78.2,68.8,9.7,71.9,81.1,81.2,81.8,72.8,93.5)
    )
colnames(x) <- c("var1", "var2")

lm(y ~ x)

identity <- diag(c(1,1,1))
b0 <- c(0, 0, 0)
lm.constrained(y, x, identity, b0)

If you just run that in R, you will notice that the unconstrained solution is similar to the linear regression solution from lm.
How you arrive to the equation is easy. You just find the arg min (y-X^Tb)^T(y-X^Tb) and solve for b.
Don't hesitate to ask anything else.  However, I actually would like to ask if anyone knows of implications of this. Obviously we lose BLUE properties. What else. Why shouldn't I do this?
A: I am also studying the Stacked regressions recently. The paper indicated that using Ridge regression with non-negetive coefficients would have better performance than best single predictor. So, I think you should consider some linear regression algorithms with regularization including Ridge regression, Lasso regression and Elastic net regression in R. I use them in python scikit-learn (Ridge, Lasso, Elastic Net). But I find that only Lasso, and Elastic Net can set the parameters positive=True. I hope I can offer an idea for you in R.
