sorry for cross-posting 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! _____________________________________ 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 [[alternative HTML version deleted]]
If you read the Posting Guide, you will see that cross-posting is deprecated on r-help ...(although not explicitly so on StackOverflow.) On Apr 25, 2012, at 4:43 PM, Fabian Roger wrote:> sorry for cross-posting > > 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! > > _____________________________________ > 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 > > > > > [[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.David Winsemius, MD West Hartford, CT
On Wed, Apr 25, 2012 at 08:43:34PM +0000, Fabian Roger wrote:> sorry for cross-posting > > 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?Hello: I am not sure, what is exactly the question. The parameters of a bivariate normal distribution are the covariance matrix and the mean vector. For the distributions above, these are mean1 <- c(5, 6) cov1 <- diag(c(1, 1)) mean2 <- c(10, 7) cov2 <- diag(c(2, 1)^2) These parameters may be used in the code above instead of mean(c), cov(c) and mean(c2), cov(c2). The curves of equal density are ellipses, whose equations may be derived from the mean vector mu and covariance matrix Sigma using the formula for the exponent in the bivariate density of normal distribution. For any fixed value of the density, the formula has the form (x - mu)' Sigma^(-1) (x - mu) = const where (x - mu)' is the transpose of (x - mu), (x - mu) is a column vector and const is some constant. The value of const may be derived using the full formula for the bivariate density, which is at http://en.wikipedia.org/wiki/Multivariate_normal_distribution In order to compute the area of this ellipse, we have to specify a required density, more exactly a lower bound on the density. The area of an ellipse is \pi a b, where a, b, are its axes. If we have two such ellipses, it is possible to compute the area of their intersection, but again, for each ellipse, a lower bound on the density is needed. Is the area of the intersection of two ellipses for some specified lower bounds on the density, what you want to compute? Petr Savicky.