[R] Zero mean correlation Matrix

Charles C. Berry cberry at tajo.ucsd.edu
Tue Oct 21 18:02:40 CEST 2008


On Mon, 20 Oct 2008, AliR wrote:

>
> Hi,,
>
> I want to use the existing cor function in R but with a different way to
> compute the correlation method.. basically zero mean correlation.
>
> The forumula I have is
>
> 'D' <- function(c1, c2)
>  sum(c1*c2, na.rm=T)/(sqrt(sum(c1*c1, na.rm=T))*sqrt(sum(c2*c2, na.rm=T)))
>
>
> I am not sure how i can modify the method cor computes its square roots and
> covariance matrixes? I only need to add this to get the answer

See

 	?crossprod

If you replace the NA's in c1 and c2 by zeroes, crossprod(c1,c2) is the 
same sum(c1*c2) which is the same as sum(c1,c2,na.rm=TRUE) was before you 
changed the NAs to zeroes.

HTH,

Chuck
>
>
>
> -- 
> View this message in context: http://www.nabble.com/Zero-mean-correlation-Matrix-tp20074044p20074044.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list