huang jialin
2012-Mar-12 15:42 UTC
[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]]
Jorge I Velez
2012-Mar-12 15:46 UTC
[R] how to calculate a variance and covariance matrix for a vector
?cov HTH, Jorge.- On Mon, Mar 12, 2012 at 11:42 AM, huang jialin <> wrote:> 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]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
R. Michael Weylandt
2012-Mar-12 15:46 UTC
[R] how to calculate a variance and covariance matrix for a vector
On Mon, Mar 12, 2012 at 11:42 AM, huang jialin <huangpsych at gmail.com> wrote:> Hello, > > I have a vector {a, b1, b2, b3, b4}.What does this mean? Is this a character vector giving names of objects that exist elsewhere in the workspace? Else, how do you tell a/b1/b2 apart in a vector? You probably want ?cov but applying it is going to depend on the shape of your data. Michael> 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]]Plain text please.> > ______________________________________________ > 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.
Doran, Harold
2012-Mar-12 15:47 UTC
[R] how to calculate a variance and covariance matrix for a vector
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: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of huang jialin > Sent: Monday, March 12, 2012 11:43 AM > To: r-help at r-project.org > 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]] > > ______________________________________________ > 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.