Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose $X \sim U(0,1)$, and $Y[x] = g(x)$ where $g(.)$ is some complicated function. I want to calculate/plot the density of $Y$. I can do this analytically for simple enough $g$.

I can also generate some large number $N$ samples of $X$ from the stardard uniform, calculate $y_i = Y(x_i)$ for each sample $x_i$, and then compute the histogram of these $ y_i, \forall i \in (1, ... N)$. This will turn out to be inefficient if, say the details of $p_Y(y)$ come from very small regions of $X$. Is there a better way to calculate/estimate $p_Y(y)$?

share|improve this question
It rather depends on what "complicated" means. If it is fairly smooth, though complicated to calculate and impossible to invert, then you could just take equally spaced values of $x$ and use kernel methods. – Henry Mar 20 '12 at 20:16
@Henry, I guess by complicated I mean that it may be less smooth in some parts, say something like$$Y[x]=\sin \frac{10}{(x+10^{-3})^2}$$ I guess I am just coming up with something that needs more samples in certain parts than others. Please don't find fault with the exact function. – highBandWidth Mar 20 '12 at 20:19

I'm not sure if this could help you, but suppose that you understand your complicated $g$ well enough to find a partition $0=t_0<t_1<\dots<t_k=1$ such that $g$ is increasing or decreasing inside each subinterval. Then, your $g$ would have a representation of the form $$ g(t) = \sum_{i=1}^k g_i(t) I_{(t_{i-1},t_i]}(t) \, . $$

Let $h_i$ denote the inverse of $g_i$, for $i=1,\dots,k$. For some fixed $i$, suppose that $g_i$ is decreasing. Then, for $t\in(t_{i-1},t_i]$, we have $$ F_Y(t) = P\{Y\leq t\} = P\{g_i(X)\leq t\} = P\{h_i(g_i(X))\leq h_i(t)\} = P\{X\leq h_i(t)\} = h_i(t) \, . $$ Otherwise, if $g_i$ is increasing, we have, $\textit{mutatis mutandis}$, that $$ F_Y(t) = P\{Y\leq t\} = P\{g_i(X)\leq t\} = P\{X\geq h_i(t)\} = 1 - h_i(t) \, . $$ Combining these results, we have $$ F_Y(t) = \sum_{i=1}^k (h_i(t))^{d_i} (1 - h_i(t))^{1-d_i} I_{(t_{i-1},t_i]}(t) \, , $$ where $d_i=1$ if $g_i$ is decreasing, and $d_i=0$ if $g_i$ is increasing. The density $f_Y$ can be found by differentiation of $F_Y$, if the $g_i$'s are smooth.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.