# [R] Bivariate normal

Thu Oct 2 00:02:57 CEST 2008

```
I think it is meaningful to ask for a non-trivial Pr (X < x, Y=y) when you
are writing down the likelihood for parameter estimation.  This is commonly
the case in likelihood estimation in bivariate failure time models.  If one
interprets Pr(Y=y) as the density evaluated y then:

Pr(X<x,Y=y) = Pr(X<x | Y=y) * f(y)

In R:

Pr(X<x,Y=y) = pnorm(x, mu=mu[1] + Sigma[1,2]*(y-mu[2])/Sigma[2,2],
sd=sqrt(Sigma[1,1] - (Sigma[1,2]^2)/Sigma[2,2])) * dnorm(y, mu=mu[2],
sd=sqrt(sigma[2,2]))

Ravi.

----------------------------------------------------------------------------
-------

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

----------------------------------------------------------------------------
--------

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Rolf Turner
Sent: Wednesday, October 01, 2008 3:20 PM
To: Sasha Pustota
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Bivariate normal

On 2/10/2008, at 4:43 AM, Sasha Pustota wrote:

> Package mvtnorm provides dmvnorm, pmvnorm that can be used to compute
> Pr(X=x,Y=y) and Pr(X<x,Y<y) for a bivariate normal.
>
> Are there functions that would compute Pr(X<x,Y=y)?

Yes:

foo <- function(x,y) {
0
}

> I'm currently using "integrate" with dmvnorm but it is too slow.

Words fail me ..... see fortune("brain surgery").

I presume you really want Pr(X < x | Y = y) rather than the probability that
X is less than x *and* Y equals y.

To find this, see any decent textbook on multivariate statistics.
(E.g. Morrison.)

You can explicitly write down the distribution of X given that Y = y.

If (X,Y) is bivariate Gaussian with mean mu and covariance matrix Sigma then
*given that* Y = y, X has a Gaussian distribution with mean

mu[1] + Sigma[1,2]*(y-mu[2])/Sigma[2,2]

and variance equal to

Sigma[1,1] - (Sigma[1,2]^2)/Sigma[2,2]

Knowing that, you can use pnorm to calculate Pr(X<x | Y=y).

cheers,

Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help