Hello everyone. I would like to find the sample covariance matrix using R. So far I read on the wikipedia what a sample_covariance is http://en.wikipedia.org/wiki/Sample_covariance according to wikipedia one vector is enough to calculate the sample covariance matrix. In R I tried cov(myvector) and I get the reply that I need to pass either two argument or one matrix with x,y values . How can I find the sample covariance matrix? Best Regards Alex [[alternative HTML version deleted]]
Alex: ?cov> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of Alaios > Sent: Thursday, November 18, 2010 12:54 PM > To: Rhelp > Subject: [R] Sample covariance matrix in R > > Hello everyone. > I would like to find the sample covariance matrix using R. > > So far I read on the wikipedia what a sample_covariance is > http://en.wikipedia.org/wiki/Sample_covariance > > according to wikipedia one vector is enough to calculate the sample covariance > matrix. > In R I tried cov(myvector) and I get the reply that I need to pass either two > argument or one matrix with x,y values . > > How can I find the sample covariance matrix? > > Best Regards > Alex > > > > > > [[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.
The help and its examples are very comprehensive here. The usage you cite shows exactly what you need to do From: Alaios [mailto:alaios@yahoo.com] Sent: Thursday, November 18, 2010 1:30 PM To: Doran, Harold Subject: RE: [R] Sample covariance matrix in R Checked that Usage covr(x, y = NULL, na.rm = FALSE, use) as you can see expectes two inputs ,,, or one with two columns.. I also found intresting this The denominator n - 1 is used which gives an unbiased estimator of the (co)variance for i.i.d. observations\ but I do not know how to use this inside the cov to get wjhat I am lloking for. Regards Alex --- On Thu, 11/18/10, Doran, Harold <HDoran@air.org> wrote: From: Doran, Harold <HDoran@air.org> Subject: RE: [R] Sample covariance matrix in R To: "Alaios" <alaios@yahoo.com>, "Rhelp" <r-help@r-project.org> Date: Thursday, November 18, 2010, 6:26 PM Alex: ?cov> -----Original Message----- > From: r-help-bounces@r-project.org</mc/compose?to=r-help-bounces@r-project.org> [mailto:r-help-bounces@r-project.org</mc/compose?to=r-help-bounces@r-project.org>] On > Behalf Of Alaios > Sent: Thursday, November 18, 2010 12:54 PM > To: Rhelp > Subject: [R] Sample covariance matrix in R > > Hello everyone. > I would like to find the sample covariance matrix using R. > > So far I read on the wikipedia what a sample_covariance is > http://en.wikipedia.org/wiki/Sample_covariance > > according to wikipedia one vector is enough to calculate the sample covariance > matrix. > In R I tried cov(myvector) and I get the reply that I need to pass either two > argument or one matrix with x,y values . > > How can I find the sample covariance matrix? > > Best Regards > Alex > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org</mc/compose?to=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]]
Alaios <alaios <at> yahoo.com> writes:> > Hello everyone. > I would like to find the sample covariance matrix using R. > > So far I read on the wikipedia what a sample_covariance is > http://en.wikipedia.org/wiki/Sample_covariance > > according to wikipedia one vector is > enough to calculate the sample covariance matrix.I'm sorry, where does it say that?? The expression given for the sample covariance is q_{ij}=\frac{1}{N-1}\sum_{k=1}^{N} \left( x_{ik}-\bar{x}_i \right) \left( x_{jk}-\bar{x}_j \right) . if N=1 this whole thing will go up in smoke: the denominator and numerator will both be zero.> In R I tried cov(myvector) and I get the reply that I need to > pass either two argument or one matrix with x,y > values . > > How can I find the sample covariance matrix? >You need more than one sample (!); even trying to do it with two samples would give you a mathematically well-defined but statistically awful estimate. I strongly suggest that you consult a statistics book or a local expert ... good luck