# If a random variable is a function, then how do we define a function of a random variable

I have sometimes seen the formulas such that $\operatorname{Var}(aX+b)=a^2\operatorname{Var} X$ and $EX^2=\sum_{x=0}^nx^2\binom{n}{x}p^x(1-p)^{n-x}$. But how do we define $aX+b$ and $X^2$ if, say $X\sim \operatorname{binomial}(n,p)$, is given? Or in general case.

• $X$ is a random number, what is the problem with doing $X^2$ or $aX+b$ ? – Stéphane Laurent Aug 22 '15 at 9:44
• In a book of mine it was said that in the first formula, $X$ is a random variable with finite variance, i.e. a mapping from a sample space $S$ into the real numbers. So if we have that $X:S\to \mathbb{R}$ then is $X^2:S^2\to \mathbb{R}$ or $2X:2S\to \mathbb{R}$? Is $S$ stable under multiplication or squaring? – verybeginner Aug 22 '15 at 9:55
• The random variable $Y=2X$ is defined by $Y(s)=2\times X(s)$ for $s \in S$. – Stéphane Laurent Aug 22 '15 at 10:00
• A cartesian product of a constant and a random variable? – verybeginner Aug 22 '15 at 10:06
• In other words, $f(X)$ is defined as $f \circ X$, and $aX+b=f(X)$ with $f(x)=ax+b$. – Stéphane Laurent Aug 22 '15 at 15:01

As an example, assume you toss a fair coin ten times and that $X$ is the number of heads. Then sometimes you will have 5 times head, sometimes 6 heads ... out of the 10 coin tosses.

The number of heads out of 10 coin tosses is thus random: you can not say in advance how many heads you will have, however you know 'something' about it: it must be somewhere between 0 and 10 heads, and for each outcome you can compute the probability that it occurs, nl the probability to observe e.g. 4 heads is $\binom{10}{4}0.5^4(1-0.5)^{10-4}$.

In this case, if you denote the number of heads that you get in ten coin tosses as $X$, then $X$ is a binomial variable of size 10 and with a success probability of $p=50\%$ so $X \sim Bin(n=10,p=0.5)$.

Now, let us analyse this further: if I toss ten coins, then I can have 4 heads in several ways : HHHHTTTTTT (Head=H, T= not head), but also TTTTTTHHHH, ...

So the random variable is a function that 'maps' the combinations of ten H/T onto a number, namely the number of H's among all 10. This is what is meant by $X: S\to \mathbb{R}$, the set $S$ is the set of all possible n-tuples (n=10) of H,T's and one such n-tupple is mapped onto a real number (hence $S \to \mathbb{R}$) by counting the number of H's among the 10.

So $X$ maps e.g. "HTTTTTTTTT" to $1$ or $X(HTTTTTTTTT)=1$, $X(HHHHHHHHHH)=10$, ...

Note that the outcome can be $1$ in several H,T n-tupples, HTTTTTTTTT, THTTTTTTTT, ... or in terms of functions, the inverse of $1$ under the function $X$ is a set of n-tupples: $X^{-1}(1)=\{HTTTTTTTTT,THTTTTTTTT, \dots TTTTTTTTTH \}$, and if you now look at the binomial densities, then the fact that $X^{-1}(1)$ is a set is excatly the reason for the factor $\binom{n}{x}$ in your formula.

So a random variable is a map that maps the outcome of a random experiment onto a real number.

What is now the random variable $5X$ ?

Well it is a random variable that is the number of heads (in 10 coins tosses) multiplied by 5. It is a random variable because you can not tell in advance what the outcome will be, you know the possible outcomes (0, 5, 10, ... 50) and for each outcome you can compute the probability.

The random variable $5X$ is a map (a function) from the set of the possible combinations of ten H/T onto a number, namely five times the number of H's among all 10.

• @f coppens A nice clarification. please also in simple terms distinction between a ranfom variable and random function. – Subhash C. Davar Aug 30 '15 at 13:35
• @subhash c. davar: I would like to do it but I must admit that I don't know a formal definition of random function, how is it defined , do you have a link or so ? – user83346 Aug 30 '15 at 14:38
• A random function would be a random variable defined on a probability space whose underlying elements are a set of functions. Certain kinds of random functions are called stochastic processes. A generalization of those is called a random field. – whuber Aug 28 '16 at 16:43
• @whuber: when you say ''A random function would be a random variable defined on a probability space whose underlying elements are a set of functions'', do you mean that the elements of the sample space $\Omega$ of the probability space $(\Omega, \mathcal{F}, \mathbb{P})$ are functions ? – user83346 Aug 28 '16 at 17:27
• Yes. The Wikipedia articles are pretty clear about that in the specific cases of stochastic processes and random fields. – whuber Aug 28 '16 at 19:39

If $X$ is a random variable, that means that $X$ is a function from a sample space $S$ to the real numbers. If $g:\mathbb{R}\to\mathbb{R}$, we can define a new random variable $Y=g(X)$, so that if $s\in S$ and $X(s)=x$ then $Y(s)=g(x)$.

So as a concrete example, let $X$ be a random variable representing the number of heads that come up in two tosses, and let $Y=X^2$. Then we have

s    | X(s) | Y(s)
TT   |   0  |    0
TH,HT|   1  |    1
TT   |   2  |    4