Quantcast

comparison of bivariate normal distributions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

comparison of bivariate normal distributions

Fabian Roger
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]]


______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: comparison of bivariate normal distributions

David Winsemius
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]]
>
> ______________________________________________
> [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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: comparison of bivariate normal distributions

Petr Savicky
In reply to this post by Fabian Roger
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.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: comparison of bivariate normal distributions

Fabian Roger
Hello Petr and thanks for your help! Thanks also for the correction on the code, of cause it is better to use the real mean and covariance than those estimated by mean() and cov(). What I am after is that if I have the two two-dimensional probability density functions of the distribution of my parameters, these functions should have an intersect. And if I know the intersect I should be able to say that a certain "volume" under both functions is shared by both comparable to the surface shared by two one-dimensional normal distributions.  From there on I was hoping to be able to say something about how high the probability is that my samples come from two different populations (in the logic of a t-test).

Would this be possible or reasonable at all?

Thank again, I really appreciate your help!

best

Fabian

Would it be possible, too to
On 26 Apr 2012, at 10:56, Petr Savicky wrote:

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.

______________________________________________
[hidden email]<mailto:[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.

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]]


______________________________________________
[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.
Loading...