# Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s

I'm working with two independent normal distributions $X$ and $Y$, with means $\mu_x$ and $\mu_y$ and variances $\sigma^2_x$ and $\sigma^2_y$.

I'm interested in the distribution of their ratio $Z=X/Y$. Neither $X$ nor $Y$ has a mean of zero, so $Z$ is not distributed as a Cauchy.

I need to find the CDF of $Z$, and then take the derivative of the CDF with respect to $\mu_x$, $\mu_y$, $\sigma^2_x$ and $\sigma^2_y$.

Does anyone know a paper where these have already been calculated? Or how to do this myself?

I found the formula for the CDF in a 1969 paper, but taking these derivatives will definitely be a huge pain. Maybe someone has already done it or knows how to do it easily? I mainly need to know the signs of these derivatives.

This paper also contains an analytically simpler approximation if $Y$ is mostly positive. I can't have that restriction. However, maybe the approximation has the same sign as the true derivative even outside the parameter range?

• I have added $\TeX$ for you. You wrote "sigma" but mentioned that these were variances, so I made them sigma-squared. Make sure it still says what you want to ask. – gung - Reinstate Monica Jul 25 '12 at 23:17
• en.wikipedia.org/wiki/Ratio_distribution has the probability density function. – Douglas Zare Jul 26 '12 at 0:38
• That's the same PDF as in the paper above. I'm trying to take the derivative of the CDF with respect to the underlying mus and sigmas. – ABC Jul 26 '12 at 1:14
• The formula of the pdf found by David Hinkley is completely in closed-form. So you can take those derivatives, one step at a time. I am actually curious about the point of doing such derivations as there is no reason the sign should be constant uniformly over the real numbers... – Xi'an Jul 26 '12 at 7:43
• @ABC You can find the density of $X/Y$ in equation 1 of this paper. I worked on it some time ago and it agrees with Hinkley's result and Marsaglia's result. It can be deduced by brute force as well as Douglas Zare suggests (I did it, only recommended if you really need to do it). – user10525 Jul 26 '12 at 9:16

• Welcome to the site, @Quantum. Would you mind giving a brief summary of these papers, so that readers can judge whether they are what they're looking for without having to open & read each one? – gung - Reinstate Monica Jan 22 '14 at 1:16
• @gung Yes, I mind ... Just kidding. These are the newest papers on the topic, containing the expression for the density of $Z=X/Y$, to the best of my knowledge. The topic is not that hot, so it's likely that this list is up-to-date unless you are reading this on year 2527. – Quantum Jan 22 '14 at 1:22
• I don't understand why the expectation of the ratio doesn't exist. If $X$ and $Y$ are jointly normally distributed with mean different than zero, then the mean of $Z = \frac{X}{Y}$ is given by $\int \int \frac{x}{y} p \left( x, y \right) dx dy$, what am I missing? – Royi Apr 13 '15 at 18:41
• Whay you are missing is the fact tha the density of $y$ is continuous and positive at zero, so that there is generated heavy tails ... – kjetil b halvorsen Aug 30 '15 at 12:16

Consider using a symbolic math package like Mathematica ,if you have a license, or Sage if you don't.

If your just doing numerical work, you might also just consider numerical differentiation.

While tedious, it does look straight forward. That is, all of the functions involved have easy to compute derivatives. You might use numerical differentiation to test your result when you are done to be sure you have the right formula.

This is the sort of problem that is very easy numerically, and less error prone as well. Since you say you only need the signs, I assume that accurate numerical approximations are more than sufficient for your needs. Here is some code with an example of the derivative against $\mu_x$:

pratio <- function(z, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) {
sd_x <- sqrt(var_x)
sd_y <- sqrt(var_y)

a <- function(z) {
sqrt(z*z/var_x+1/var_y)
}

b <- function(z) {
mu_x*z/var_x + mu_y/var_y
}

c <- mu_x^2/var_x + mu_y^2/var_y

d <- function(z) {
exp((b(z)^2 - c*a(z)^2)/(2*a(z)^2))
}

t1 <- (b(z)*d(z)/a(z)^3)
t2 <- 1.0/(sqrt(2*pi)*sd_x*sd_y)
t3 <- pnorm(b(z)/a(z)) - pnorm(-b(z)/a(z))
t4 <- 1.0/(a(z)^2*pi*sd_x*sd_y)
t5 <- exp(-c/2.0)
return(t1*t2*t3 + t4*t5)
}

# Integrates to 1, so probably no typos.
print(integrate(pratio, lower=-Inf, upper=Inf))

cdf_ratio <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) {
integrate(function(x) {pratio(x, mu_x, mu_y, var_x, var_y)},
lower=-Inf, upper=x, abs.tol=.Machine$double.eps)$value
}

# Numerical differentiation here is very easy:
derv_mu_x <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) {
eps <- sqrt(.Machine\$double.eps)
left <- cdf_ratio(x, mu_x+eps, mu_y, var_x, var_y)
right <- cdf_ratio(x, mu_x-eps, mu_y, var_x, var_y)
return((left - right)/(2*eps))
}