[R] *Building* a covariance matrix efficiently

From: Tsjerk Wassenaar <tsjerkw_at_gmail.com>
Date: Mon, 14 Mar 2011 15:13:44 +0100


deaRs,

I want to build a covariance matrix out of the data from a binary file, that I can read in chunk by chunk, with each chunk containing a single observation vector X. I wonder how to do that most efficiently, avoiding the calculation of the full symmetric matrices XX'. The trivial non-optimal approach boils down to something like:

Q <- matrix(rnorm(100000),ncol=200)
M <- matrix(0,ncol=200,nrow=200)
for (i in 1:nrow(Q))
  M <- M + tcrossprod(Q[i,])

I would appreciate pointers to help me fill this lacuna in my R skills :)

Cheers,

Tsjerk

-- 
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group

* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen The Netherlands ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Mon 14 Mar 2011 - 14:17:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 17:00:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive