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]] ______________________________________________ [hidden email] 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. |
Alex:
?cov > -----Original Message----- > From: [hidden email] [mailto:[hidden email]] 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]] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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:[hidden email]] 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 <[hidden email]> wrote: From: Doran, Harold <[hidden email]> Subject: RE: [R] Sample covariance matrix in R To: "Alaios" <[hidden email]>, "Rhelp" <[hidden email]> Date: Thursday, November 18, 2010, 6:26 PM Alex: ?cov > -----Original Message----- > From: [hidden email]</mc/compose?to=[hidden email]> [mailto:[hidden email]</mc/compose?to=[hidden email]>] 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]] > > ______________________________________________ > [hidden email]</mc/compose?to=[hidden email]> 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]] ______________________________________________ [hidden email] 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. |
In reply to this post by alaios
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 ______________________________________________ [hidden email] 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. |
perhaps ...
library("fortunes") fortune("surgery") Cheers, Bert On Thu, Nov 18, 2010 at 1:57 PM, Ben Bolker <[hidden email]> wrote: > 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 > > ______________________________________________ > [hidden email] 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. > -- Bert Gunter Genentech Nonclinical Biostatistics ______________________________________________ [hidden email] 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. |
Powered by Nabble | Edit this page |