Hi, Thanks for your response.
I tried to use cov() before, but got NA all over the place. a and b1 are scalars in the example. So that is the problem. I will start over from the formula. Thanks again. Sincerely, Jialin Huang On Mon, Mar 12, 2012 at 10:47 AM, Doran, Harold <[email protected]> wrote: > Can you provide sample data? This suggests that a and b1, for example, are > scalars. If that is what you actually have then you cannot produce a > covariance between two scalars. > > > -----Original Message----- > > From: [email protected] [mailto:[email protected]] > On > > Behalf Of huang jialin > > Sent: Monday, March 12, 2012 11:43 AM > > To: [email protected] > > Subject: [R] how to calculate a variance and covariance matrix for a > vector > > > > Hello, > > > > I have a vector {a, b1, b2, b3, b4}. How can I calculate the following > > matrix: > > > > var(a) cov(a, b1) cov(a, b2) cov(a, b3) cov(a, b4) > > cov(a, b1) var(b1) cov(a, b2) cov(a, b3) cov(a, b4) > > ... > > ... > > cov(a, b1) cov(a, b2) cov(a, b3) cov(a, b4) var(b4) > > > > I would very appreciate your inputs. Thank you very much. > > > > Sincerely, > > Jialin Huang > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > [email protected] 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. > [[alternative HTML version deleted]] ______________________________________________ [email protected] 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.

