Sorry that I didn't see that you revised your original code. Yes, Ian's method will work, although it is slightly more efficient to use the # operator to avoid forming the diagonal matrix: do j=1 to p; x=data-data[,j]; mat=mat+x*(weights[,j]#t(x)); end; (For an explanation, see Converting between correlation and covariance matrices - The DO Loop ) If you determine that the weights are positive, the you can use do j=1 to p; x=(data-data[,j])#sqrt(t(weights[,j])); mat=mat + x*x`; end;
... View more