📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

Functions of a Random Variable

Steve Brunton13:36

Transcription

Welcome back. Today I'm going to introduce the idea of building functions of a random variable X. So these are functions like, uh, G of X. Um, so I'm going to introduce a new random variable Y that is a function of my random variable X. This is a really important concept. This is one of the reasons we wanted to define random variables in the first place: to take that abstract step of introducing a variable is so we can do things like build functions of that variable. So tons of examples here. Um, really, really simple one: let's say that I collect data um of temperature in Fahrenheit, and I want to convert it to Celsius. So my temperature distribution in Celsius is a function of my temperature distribution in Fahrenheit. That's a really, really simple example.

Or, um, let's say that I have a normal distributed variable X, and I want to compute the distribution of X squared. Um, so G(X) would be X^2. How do I do that? And it's not quite as simple as just taking the probability density function, the PDF, of X and plugging it into this function G. That's not actually going to give you a well-defined probability density for Y. So there's a slightly more involved set of steps to get the probability distribution function of Y, given that we have a PDF of X.

Some other cool examples I think are important, um, that we'll do later: let's say X is the distribution of, uh, you know, uh, velocities of particles of gas in the air. So this would be distributed by Maxwell's distribution, okay? And let's say that I want to, uh, understand what's the distribution of kinetic energy in the room. So Y would be (1/2)Mass x^2. If X is the velocity, then the kinetic energy is (1/2)mv^2. So I want to be able to build functions of my random variables and do analysis on those functions. So that's what we're going to do today. And I'm just going to remind you of some basic, basic notation.

Um, for my variable F, we have a probability density function; we have a PDF, a probability density function. I'm going to do this in continuous, uh, for continuous random variables like the normal distribution or the exponential distribution, but this also totally works for discrete random variables. I'm just going to do this for continuous random variables. So the PDF, the probability density function, we're just going to denote by this, uh, little f subscript X. That indicates that it's the PDF of my function X, of my random variable X. And so this could be like a normal distribution. And remember the CDF, the cumulative density function, is essentially—we're going to call this capital F—it is the probability that my random variable X is less than some value little x. Okay? And this is equal to the integral from negative infinity to little x of my PDF, my probability density function. So essentially this PDF, for continuous random variables, tells me the probability of being in a little infinitesimal dx sliver, um, around a value X, and I can integrate that up to get the cumulative density. For example, to know what is the probability that my variable is less than some value X. And we've totally looked at this before. So, for example, if my PDF is a Gaussian, normal distributed variable, then my CDF, my cumulative density function, is going to be this kind of sigmoidal error function. Okay, good. This is all background; we know this.

And so in my new random variable Y, which is a function of X, we want to derive its own PDF and CDF. And so we're going to call the PDF of Y, uh, f subscript Y, and the cumulative density of Y we're going to call F subscript Y. Good. We've established the notation, and now what we're going to do is we're going to try to get functions for these, uh, things that we want in terms of these things that we have and this function G. Okay. Uh, and again, I'm just telling you this is important: you can't get F of Y by just taking the density of X and plugging it into this function G. That doesn't work. You can't take a normal distribution, plug it into, you know, G = x^2; you can't just square the normal distribution and get the distribution of X^2. Doesn't work like that. Um, in fact, I think you should try it and see what goes wrong—like, what could go wrong. Give it a try; play around with this, and you'll realize you can't go directly from PDF to PDF, but you can go from CDF to CDF. Um, and so I'm not going to tell you exactly why that's true, but that is, uh, that turns out to be the way that you solve these problems. So we're going to take the cumulative density that we know to build, uh, the cumulative density that we don't know, and then from the CDF we can essentially recover our PDF, our probability density function, by taking the derivative with respect to Y. So if we take, uh, d/dy of this function, we will recover our probability density. So you go—you integrate to go from PDF to CDF; you differentiate to go from CDF to PDF. Good. Okay. So that's enough abstraction. I'm going to give you some examples now. Why would we do this? What are some examples? How does it work? Okay.

Um, so I think the first example I'm going to give you is that, uh, converting temperature from, uh, from Fahrenheit to Celsius or Celsius to Fahrenheit, which is a pretty nice intuitive, intuitive example here. So I'll just give myself some space. So my first example: let's say that I have a random variable X that is a normally distributed variable. So we're going to say that it is a normal variable with mean mu and standard deviation sigma. And let's say that we want a random variable Y—maybe I'll make this, uh, pink—we want a random variable Y that is just a constant times X: aX + b. Okay? This is essentially, you know, if I want to go from Celsius to Fahrenheit, I multiply by 9/5 and I add 32. Why would you ever do that? I don't know; most of the world uses Celsius; we use Fahrenheit here in the US, but it's an easy way to convert, um, Celsius to Fahrenheit: multiply by 9/5, add 32. So what if I have a distribution of temperatures? How do I take my distribution of temperatures in Celsius and map it to a distribution of temperatures in Fahrenheit? That's a pretty, uh, intuitive, simple example. So how do I build this distribution? First thing I want to convince you of: we know that this normally distributed variable has area under the curve equal to one. The area under the curve is one because this is a well-defined probability. If you add up all of those probabilities, something has to happen, meaning the probabilities add up to one. And if I just took that PDF and multiplied by a and added b, I'm going to get something that does not have area under the curve equal to one. Okay? It might not even be defined if I just define this function. So we have to do something a little bit different. I'm assuming a is positive here, but it doesn't, uh, matter that much. So what we're going to do instead—I said we're going to take the CDF; we're going to build us a cumulative density function for Y, and then we're going to recover the PDF of this variable Y.

So the cumulative density function for Y, um, in fact, I'm going to keep it with pink here: F sub Y, um, of my little variable y, is the probability that my new random variable capital Y is less than—and I don't know if it's less than or equal to, since these are infinitesimals, it doesn't really matter—the probability that my variable is less than Y, which is the same as the probability that this thing is less than y. This is the same as the probability that my aX + b is less than y. Now this is probably representable in terms of my CDF of X. I'm going to subtract b from both sides, divide by a, and now I have the probability that X is less than something, which is a lot easier for me to deal with. So this is the probability that, uh, my random variable X is less than (y - b)/a. And that, in fact, is my CDF of my X variable. I know this cumulative distribution, uh, for (y - b)/a. I just plug in this value here, and I get the exact same probability of my cumulative distribution function of Y evaluated at little y. Good. So now I actually know that this CDF for, for Y can be related to the CDF for X. This is well defined; this nothing funny happened here; this is well defined. And now I can take the derivative of this function with respect to Y to recover my PDF for Y. Um, and maybe I'll just do that in my, um, kind of last, uh, color here: blue. So now, uh, little f sub Y of my function y is just d/dy; it's d/dy of my cumulative density function, but I can write my cumulative density function in terms of this function, uh, of a variable y. So this is of, uh, F sub X((y - b)/a). And this is pretty easy—you know, the chain rule—this is just, um, you know, the derivative of this evaluated here times the derivative of the stuff inside with respect to Y. So I get a factor of 1/a. This is 1/a times the derivative of this thing is just f sub x((y - b)/a). Okay? So this is the answer. You could stop here; you could say now I know the CDF of Y and I know the PDF of Y in terms of functions that I can write down explicitly. So I can actually write these down. And if you wanted to, you could say, well, we know that this is a normally distributed variable; I could even write out the Gaussian normal distribution: e to the minus whatever (y - b)/a^2 over sigma squared, etc., etc. Um, and you can verify yourself that this works out to Y being itself normally distributed with parameters a mu + b—that's the new mean—and the new standard deviation is going to be a^2 sigma^2. So I'll let you work out this very, very last step here, but you see the procedure. The basic, basic procedure is you can't start with a PDF and go to a PDF; you have to kind of bypass that and go this long way. You have to use the CDF of X to get the cumulative distribution function of Y. This makes sense; it's well defined, and it allows me to write the CDF of Y in terms of a CDF of X, and then if I take its derivative, I recover my PDF of this new variable Y. Really, really straightforward, um, kind of simple idea here. Okay.

Um, and there's a lot of things you can do with these random variables. So maybe what I'm going to do is in another video I'll do two things. Um, I'll show you what's called the chi-squared distribution. So if X, uh, is normal, and let's say it's just a standard unit normal, um, mean zero, standard deviation one, then what is Y, uh, equal to X^2? What's that distribution? Okay? And again, it's not just taking the normal and plugging it into—squaring the normal—you have to go through this, this long way procedure to recover what's called the chi-squared distribution. Um, and chi-squared distributions are super, super important in statistics. They are what allow me to test whether or not two distributions are the same or whether or not data fits with the distribution I was expecting to get, um, through some other modeling or analysis. So this is super important; we'll do this in the next video. And I'll also show how you can go from a normal, uh, with mean mu and, and, um, variance sigma squared and kind of scale that into a normal distribution with mean zero and standard deviation one. And that's going to be really, really useful for computations. If I have a normal distribution that has some mean and some standard deviation, often I'll want to map it into the standard unit normal, do computations there, and then map it back. And it turns out it's actually this, uh, formula we derived will be how we do that. Okay. So that'll be the next lecture—kind of part two of functions of a random variable—where we introduce chi-squared and we talk about how to go back and forth between these two normals, how we pick a and b, um, to make this mean zero and this standard deviation one, and then what you can do with it. Okay. Thank you.