I'm having difficulties using R's quadprog
library to implement weighted least squares with 2 restrictions. The first restriction is that all the coefficients need to be greater than or equal to 0. The second restriction is that the coefficients need to sum to 1.
More formally, I am trying to minimize with respect to W the following equation: (Y - XW)^T * V * (Y - XW), where V is a diagonal matrix.
Y is (p x 1), X is (p x s), W is (s x 1), and V is diagonal (pxp). Below is a reproducible example: I am trying to find the proper parameters to use with quadprog::solve.QP
library(quadprog)
set.seed(1)
y = rnorm(100)
X = matrix(nrow = 100, ncol = 3)
for (i in 1:ncol(X)) {
X[,i]<- rnorm(100, mean = i)
}
v_vec = rnorm(ncol(X))
V = diag(v_vec)