[R] regression constraints (again)
Brett Robinson
brett at rebcon.co.uk
Sun Aug 24 13:02:54 CEST 2003
Im trying to do regressions with constraints that the weights
are all >=0 and sum(weights) = 1. I've read the archive and have
set the problem up with solve.QP and just the non-negativity constraints
along the lines of:
y as the data vector
X as the design matrix
D <- t(X) %*% X
d <- t(t(y) %*% X)
A <- diag(ncol(X))
b <- rep(0,ncol(X))
fit <- solve.QP(D=D,d=d,A=t(A),b=b,meq=0)
(as per Gardar Johannesson '01)
When I try to add the extra constraint that sum(weights)=1 I get errors
owing to incompatibility of matrices. I add the constraint by putting an
extra column of all ones to A and setting meq=1.
I can work round it I think, by using an intercept and using the extra
column on the matrix for the sum(weights) constraint but I think that it
should be possible without doing this.
Grateful for any pointers as to where I am going wrong.
Brett Robinson
More information about the R-help
mailing list