r - Weighted Least Squares with constraints on coefficients using quadprog -
i'm having difficulties using r's quadprog
library implement weighted least squares 2 restrictions. first restriction coefficients need greater or equal 0. second restriction coefficients need sum 1.
more formally, trying minimize respect w following equation: (y - xw)^t * v * (y - xw), v diagonal matrix.
y (p x 1), x (p x s), w (s x 1), , v diagonal (pxp). below reproducible example: trying find proper parameters use quadprog::solve.qp
library(quadprog) set.seed(1) y = rnorm(100) x = matrix(nrow = 100, ncol = 3) (i in 1:ncol(x)) { x[,i]<- rnorm(100, mean = i) } v_vec = rnorm(ncol(x)) v = diag(v_vec)
Comments
Post a Comment