[R] X'W in Matrix

Rafael A. Irizarry ririzarr at jhsph.edu
Fri Jun 9 05:43:56 CEST 2006


Hi!

I have used the Matrix package (Version: 0.995-10) successfully 
to obtain the OLS solution for a problem where the design matrix X is 
44000x6000. X is very sparse (about 80000 non-zeros elements).

Now I want to do WLS: (X'WX)^-1X'Wy

I tried W=Diagonal(length(w),w) and
wX=solve(X,W)

but after various minutes R gives a not enough
memory error (Im using a 64bit machine with 16Gigs of RAM).

I ended up doing this:
wX=Matrix(as.matrix(X)*sqrt(w),sparse=TRUE)
coefs1=as.vector(solve(crossprod(wX),crossprod(X,w*y)))

which takes about 1-2 minutes, but it seems a better way, using the 
diagonal matrix, should exist. If there is I'd appreciate hearing it. If 
not, Im happy waiting 1-2 minute x #of iters.


Thanks,
Rafael



More information about the R-help mailing list