[R] compare bivariate normal distributions
Fabian Roger
fabian.roger at bioenv.gu.se
Mon Apr 23 14:18:57 CEST 2012
Dear all,
I have tow (several) bivariate distributions with a known mean and variance-covariance structure (hence a known density function) that I would like to compare in order to get an intersect that tells me something about "how different" these distributions are (as t-statistics for univariate distributions).
In order to visualize what I mean hear a little code example:
########################################
library(mvtnorm)
c<-data.frame(rnorm(1000,5,sd=1),rnorm(1000,6,sd=1))
c2<-data.frame(rnorm(1000,10,sd=2),rnorm(1000,7,sd=1))
xx=seq(0,20,0.1)
yy=seq(0,20,0.1)
xmult=cbind(rep(yy,201),rep(xx,each=201))
dens=dmvnorm(xmult,mean(c),cov(c))
dmat=matrix(dens,ncol=length(yy),nrow=length(xx),byrow=F)
dens2=dmvnorm(xmult,mean(c2),cov(c2))
dmat2=matrix(dens2,ncol=length(yy),nrow=length(xx),byrow=F)
contour(xx,yy,dmat,lwd=2)
contour(xx,yy,dmat2,lwd=2,add=T)
##############################################
Is their an easy way to do this (maybe with dmvnorm()?) and could I interpret the intersect ("shared volume") in the sense of a t-statistic?
Thanks a lot for your help!
sincerely,
_____________________________________
Fabian
Fabian Roger, Ph.D. student
Dept of Biological and Environmental Sciences
University of Gothenburg
Box 461
SE-405 30 Göteborg
Sweden
Tel. +46 31 786 2933
More information about the R-help
mailing list