[R] Sample covariance matrix in R

Bert Gunter gunter.berton at gene.com
Thu Nov 18 23:25:33 CET 2010


perhaps ...

library("fortunes")
fortune("surgery")


Cheers,
Bert

On Thu, Nov 18, 2010 at 1:57 PM, Ben Bolker <bbolker at gmail.com> 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
>
> ______________________________________________
> 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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics



More information about the R-help mailing list