# PDF of a log-normally distributed variable after tangens hyperbolicus transformation

Assume a variable $$x_0>0$$ with log-normally distributed noise, such that the observation $$x$$ of $$x_0$$ has the following PDF:

$$p(x\mid x_0) = \frac{1}{\sqrt{2\pi}\sigma x}e^{-\frac{\left(\ln{(\frac{x}{x_0})} - \sigma^2\right)^2}{2\sigma^2}}$$

(NB: $$x_0$$ thus corresponds to the mode of the log-normal distribution, following the reparameterization $$\mathrm{mode}=e^{\mu-\sigma^2}$$)

As it turns out, I cannot measure $$x$$ directly, but only a transformation $$y(x)$$:

$$y(x) = (1-\delta)\tanh(\beta x) + \delta$$

The parameters $$\delta$$ and $$\beta$$ are not relevant to my question, but it can be assumed $$0\le\delta\le1$$ and $$\beta>0$$.

Now I have a measurement $$y_m$$ and I want to compute the probability that a latent variable $$x_0$$ would generate a $$y$$ within the window $$[y_m-\epsilon; y_m+\epsilon]$$.

I have two questions related to this:

1. What is the PDF for $$y$$ that would allow me to compute this probability? (Note that for reasons not mentioned here, I want to avoid transforming $$y_m$$ to $$x$$-space)
2. More pragmatically, the scientific programming module I am using (scipy.stats.lognorm) has CDF implementations for the log-normal distribution. If instead of the above $$\tanh$$ transformation I had the identity transformation $$y(x)=x$$, I could simply use something along the lines of lognorm(x0,σ).cdf(y_m+ε) - lognorm(x0,σ).cdf(y_m-ε). Can I still use this lognorm CDF implementation after some appropriate transformation?
• If $y(x)$ is observed/known, so is $x$ (for a given $(\delta,\beta)$ Sep 7, 2020 at 12:56
• Yes, that's correct, but as mentioned in 1., I want to avoid back-transforming $y_m$ to $x$-space (the reason is that I have other y(x) that are not so easily invertible). I'm starting to think though that the PDF of $y$ will require computing $y^{-1}$. Sep 7, 2020 at 13:04

The hyperbolic tangent function $$\tanh$$ is a strictly increasing function, so it is quite simple to get the CDF of the random variable $$Y$$. I am going to give a more general answer that what you are looking for --- specifically, I will not make any assumption about the distribution $$X$$, and I will not assume that this is a non-negative random variable. Using the stipulated transformation with $$\beta$$ and $$0 \leqslant \delta < 1$$ you have:

\begin{align} F_Y(y) &\equiv \mathbb{P}(Y \leqslant y) \\[12pt] &= \mathbb{P}((1-\delta) \tanh (\beta X) + \delta \leqslant y) \\[6pt] &= \mathbb{P} \bigg( \tanh (\beta X) \leqslant \frac{y-\delta}{1-\delta} \bigg) \\[6pt] &= \mathbb{P} \bigg( \frac{e^{2 \beta X}-1}{e^{2 \beta X}+1} \leqslant \frac{y-\delta}{1-\delta} \bigg) \\[6pt] &= \mathbb{P} \bigg( e^{2 \beta X}-1 \leqslant \frac{y-\delta}{1-\delta} \cdot (e^{2 \beta X}+1) \bigg) \\[6pt] &= \mathbb{P} \bigg( e^{2 \beta X} \cdot \frac{1-y}{1-\delta} \leqslant 1 + \frac{y-\delta}{1-\delta} \bigg) \\[6pt] &= \mathbb{P} \bigg( e^{2 \beta X} \cdot \frac{1-y}{1-\delta} \leqslant \frac{1+y-2\delta}{1-\delta} \bigg) \\[6pt] &= \mathbb{P} \bigg( e^{2 \beta X} \cdot (1-y) \leqslant (1+y-2\delta) \bigg). \\[6pt] \end{align}

Taking account of the limits of the function you then have:

\begin{align} F_Y(y) &= \begin{cases} 0 & & \text{if } y \leqslant 2\delta-1, \\[6pt] F_X \bigg( \frac{1}{2 \beta} \cdot \log \Big( \frac{1+y-2\delta}{1-y} \Big) \bigg) & & \text{if } 2\delta-1 < y < 1, \\[6pt] 1 & & \text{if } y \geqslant 1, \\[6pt] \end{cases} \\[6pt] \end{align}

It is easily shown that:

\begin{align} \frac{d}{dy} \log \Big( \frac{1+y-2\delta}{1-y} \Big) &= \frac{1}{1+y-2\delta} + \frac{1}{1-y} \\[6pt] &= \frac{(1-y)+(1+y-2\delta)}{(1+y-2\delta)(1-y)} \\[6pt] &= \frac{2(1-\delta)}{(1+y-2\delta)(1-y)}. \\[6pt] \end{align}

Therefore, differentiating the CDF with respect to $$y$$ gives the corresponding density:

$$f_Y(y) = \frac{(1-\delta)}{(1+y-2\delta)(1-y) \beta} \cdot f_X \bigg( \frac{1}{2 \beta} \cdot \log \Big( \frac{1+y-2\delta}{1-y} \Big) \bigg) \quad \quad \text{for } 2\delta-1 < y < 1.$$

Substitution of the density function for $$X$$ will give you the final form. Note that in your problem you have assumed that $$X$$ is a non-negative random variable, which leads to the effective bound $$y \geqslant \delta$$. This bound emerges correctly from substitution into the above equation in the case where $$f_X$$ has support only over positive argument values.

• Thanks! To confirm my understanding of your answer: this essentially corresponds to solving $y_m = (1-\delta)\tanh(\beta x_m)+\delta$ for $x_m$ and then computing the CDF of $x_m$ in x-space using the known $p(x\mid x_0)$ (using the terminology of my OP)? Sep 7, 2020 at 15:00
• I could not make sense of your $p(x|x_0)$ so I did not do that last step. But yes, that is essentially the method.
– Ben
Sep 7, 2020 at 22:33
• Ok, thanks. $p(x|x_0)$ is the log-normal distribution following the reparameterization $\mu = \ln{(x_0)}+\sigma^2$, where $x_0$ is the mode of the log-normal. Sep 8, 2020 at 9:36
• Elegant answer (+1) Sep 9, 2020 at 7:43
• My answer is more general than that --- it does not assume that $X$ is non-negative. However, if you substitute any $y < \delta$ into the final equation you get $\log (\tfrac{1+y-2\delta}{1-y}) < 0$ so the argument for the density $f_X$ is negative. Thus, if $X$ is non-negative then you get zero density for $Y$ for all $y<\delta$. I have updated my answer to specify my assumptions more clearly.
– Ben
Sep 15, 2020 at 0:57