Now that we've talked about measures of central tendency like mean median and mode and measures of spread
like range and IQ are interquartile range.
We want to talk about this idea of transforming a random variable because if we have, for instance,
a data set and we already know all of these measures about the data set, so let's just make up some
values.
Let's say that for this particular data set, we know that the mean is six, that the median is seven,
the mode is three, and we'll just say the range in IQ R are ten and eight.
And let's say we also just have some standard deviation.
What we want to say now is that if we shift the data set by some constant value, we'll call it K,
Then our shifted data set is only going to see the mean meeting and mode.
B shifted the range and interquartile range and standard deviation for that matter will still stay the
same.
So if we shift the data set by some constant K, then the mean and let's say the shift is adding K to
every value in the data set, then the mean of this new shifted data set will be six plus K.
In other words, the mean will change.
The median will also be seven plus K, the median will change and the mode will change.
The mode will be three plus K, but the range and the interquartile range won't be affected by the shift
of adding K to the data set.
The range and interquartile range will still be ten and eight and the standard deviation is also not
affected.
So the standard deviation will still just be equivalent to the standard deviation from the original
data set.
And the reason for that, if we think about it, we could sketch a hypothetical probability distribution
for the original data set.
Let's say that the distribution for the original set looks something like this.
So this is the probability distribution for this set of data, in which case we could maybe indicate
here the mean and the standard deviation.
So the mean in this case for this original set is six.
And then we have our standard deviation here, shifting the data set by adding some value K to every
point in the data set means that this whole distribution gets shifted to the right by K units.
So we could visualize this shifted distribution here and we would say that the shift of K units is this
distance right here.
So this is a shift of K, and so we would have our new distribution and we would show there it's mean
and standard deviation.
In other words, let's say that some of the values in our original data set, we see that the mode is
three.
So we know that this original dataset has to include values of three, the median is seven.
So the data set might include values of seven, it might not.
But let's just say that some of the data points in this original data set are three, three, seven,
ten, 12 and those are just a few examples.
If we add some value of K to each data point in the data set, then three of course is going to become
three plus K, So this will be three plus K, this is going to be seven plus K and we'll have ten plus
K and here 12 plus K, And these then are the values in the new shifted dataset.
So if we call this data set X and we call this data set Y, then these are the values in the dataset
X and these are the values in the data set Y.
If we knew that K was equal to, let's say, five, then we would know that these values were eight,
eight, 12, 15 and 17.
But just for some generic K, we can express the values in the shifted data set is three plus K, seven
plus K, etc. And so practically that means that every value in our original data set, if we can think
about maybe a data point here, maybe that's the value three in the original data set, maybe we have
a data point here of seven.
Then when we add K to that value, we're going to shift over to the corresponding value three plus K
right here in the new data set, we're going to shift over a distance of K to this new value in the
new data set.
And so because of that shift, we can see how the mean is going to move from the mean in the original
data set to that mean plus K to get to this mean in the second data set in the shifted data set, the
median will also move because the whole data set moves over and the mode just represents a single point
in the set.
So if this was the point representing the mode right here, when we shift the data set over, of course
that mode is going to shift as well.
But you can imagine that the range and.
The interquartile range won't change because the spread of the data doesn't move.
The whole set just gets shifted over by the same amount, but the width of this probability distribution
won't change at all.
If the range here was ten and let's say the range of ten spans from the lowest value in the set, which
maybe is two to the highest value, which may be is 12.
And that's why we're getting a range of ten.
Let's say that the minimum and maximum values in this set are two and 12.
So we have a range of ten.
If K is five, then two and 12 become seven and 17, then the range is still ten because the spread
of the data is still the same.
We just went from 2 to 12 over to 7 to 17 and the same with the IQ.
R.
The IQ r is also a measure of spread.
It's not going to change because the width of the data distribution doesn't change when we shift the
data set by some constant K.
So that's the idea of shifting a data set, the idea of scaling a data set.
So let's say we start with again this same data set with the same values.
So the mean is six, median is seven, mode is three, the range is ten eight and some generic standard
deviation.
So we have our original data set.
If we scale the data set, meaning instead of adding some positive constant K to create a shift, we're
going to multiply by some constant k.
For instance, if K is two, that means we're going to double every value in the original data set to
get the scaled data set.
If K is one half, that means we're going to divide in half or have every value in the original data
set.
So in that case then the scaled data set, if we're scaling by some value, K just like with the shift,
the mean median and mode will all get scaled.
So the mean now will be given by six K, the median will be given by seven K, the mode will be given
by three K.
But here's the difference now the range and the interquartile range are also affected by scaling, even
though they aren't affected by shifting.
So the range now will be ten K and the interquartile range will be eight K, If the original range in
interquartile range were ten and eight, The standard deviation is also affected by the scaling.
So the standard deviation will also need to be multiplied by K.
And we can see why this scaling is true.
Because if we took a super simple data set, let's say we started with a data set, there's just two
data points which are five and six.
So not the set described by these values here, but just a two data point data set, one values five,
the others six.
If we say that K is two and we scale up our data set by a factor of two, then our new data set is ten
and 12.
Well, the mean over here is five and one half.
The mean over here is 11.
So we can see that the mean also doubles in the same way that the actual data itself doubled.
The median over here is five and a half.
The median over here is 11.
So that doubled as well.
The mode there is no mode, but we can see that even if there was a mode.
So let's say there was some other value here of five.
Now the mode is five.
The new data set would be ten, ten, 12, the mode would be ten in the scale data set compared to five
in the original data set, it got doubled as well.
But then here's where we see the range.
So ignoring this again here, the range is one because six minus five is one.
And when we double those values, the range doubles from 1 to 2 because 12 minus ten is two.
So the range is affected.
The interquartile range, we don't really have enough to calculate here, but we can see that if the
range expands, then of course the interquartile range is also going to expand.
And then our standard deviation, same thing.
It's also a measure of spread.
It's going to be affected by the scaling and we see that with the data distribution.
So let's say that this is the distribution of our original data set.
We could identify here the mean and then the standard deviation in this original set, scaling the data
set by some factor.
If K is greater than one, that means we're increasing all of the values in the set.
And so what that's going to do is stretch out this distribution horizontally.
It's almost as if we grab the right hand side of this distribution and we pull it to the right so that
this whole thing stretches out.
You can imagine as we stretch it out, it's going to get flatter.
The vertical height of it will decrease because we have the same amount of area here that we're working
with, the same amount of area under the curve.
And if we stretch this out to the right, we're just distributing it over a larger interval, over a
larger range.
So that stretched out distribution might look something like this with its mean and standard deviation.
And we can see here with this stretch, notice how this.
Standard deviation itself actually gets stretched, this standard deviation.
Here we have a shorter distance, whereas in the stretched data set, the standard deviation gets stretched
out.
We can see here too, if we think about this point here where the boundary of that single standard deviation
intersects the curve and maybe the symmetric point right here, we could see that width.
If we look at the same width along this curve.
So maybe that's this point.
And then roughly, let's say this point right here and we connect those, we can see how the width of
just one standard deviation around the mean is larger than this width of one standard deviation around
the mean.
So everything about the spread, the range, the interquartile range and the standard deviation are
going to increase.
They're going to stretch out by whatever factor K is indicating if K is less than one.
Of course, then this original distribution gets compressed even further, which means it's going to
get taller instead of shorter.
This way it's going to get taller and get compressed into a narrower range.
But for values of K greater than one, we stretch out the distribution and all of those measures of
spread get stretched out as well.
So the takeaway here is just to realize that only mean median and mode are affected by a shift.
But all of these measures mean median mode and range I.Q., R and standard deviation are all affected
by scaling.
So with that in mind, let's look at sort of a real world example so that we can understand how this
affects data in real life.
In this example, let's say that we're running a dropshipping business, so we're not the manufacturer
who's actually creating the product.
We have a separate manufacturer, they are producing the product, but then they send it to us and our
responsibility is to just ship it out.
So we are paying the manufacturer for the privilege of that shipping business.
So we're getting paid by the manufacturer to ship out their product.
But they're also asking us to pay a small upfront fee for the privilege of doing business with them
and so that they're not sending us a bunch of product to ship.
Then we fail to ship it and they get left with a bunch of us shipped product and lose a bunch of money.
So the arrangement that we've agreed on here is that we will pay the manufacturer $2 per package or
per item and they will pay us, or we will receive $10 for every pound of product that we ship out.
So what we know about the product that we're getting from the manufacturer is that the items that they
manufacture and the things that they want us to ship come in only three weights.
There's a £1 product, a £2 product and a £5 product.
So what we do is we create this discrete random variable X that models the weight of product.
So X can only take on the values one, two or five.
There are no in between values.
There's no one and one half pound package, there's no £4 package.
We only have the £1 package.
And then maybe this is a two item bundle in a five item bundle.
But the package weights that we get can only be a £1, £2 or £5 package.
And these are the rates at which customers purchase these items or these bundles.
So 60% of customers purchase the £1 item, £1 package, 30% of customers purchase the £2 bundle and
10% of customers purchase the £5 bundle, which means that the manufacturer, when they are sending
us product to ship out, 60% of what we're getting from them is these little £1 packages, 30% is the
£2 packages and 10% is the £5 packages.
So we can say the probability of us receiving from the manufacturer and shipping out to the customer.
Any particular item here is given by these values.
What we want to do is calculate a mean or an expected value and a standard deviation value for the amount
of money we can expect to make based on this payment structure.
So in order to do that, the first thing that we want to do is compute the expected value of the number
of pounds were sending out to customers the weight of all the product that we're shipping to customers.
So what we can say is that our expected value, the expected value of our variable x here, which models
the weight of product, is going to be the mean of this variable here.
And remember that when we have a discrete random variable like this, what we have to do is find the
weighted mean, which means that we have to say for the £1 packages, there's a 60% chance that we're
sending out one of those for the £2 packages.
There's a 30% chance we're sending out one of those.
And for the £5 packages, there's a 10% chance that we're shipping out.
One of those packages.
So when we multiply here, we get 0.6 plus 0.6 plus 0.5 or 1.7, which means that on average for every
package we ship out, we're shipping out about £1.7 of product, even though the only values we're actually
shipping out are £1, £2 and £5 packages.
If we average out all the packages we're shipping, our mean weight is £1.7, then our variance.
For this discrete random variable is going to be the difference between each of these weights one,
two and five and the mean.
So we'll say we'll take the first weight here.
We'll say one minus the mean of 1.7.
We square that value and we multiply it by the probability of that particular weight.
So 0.6 and then we do that for all of the weights that we have, all of the values that X can take on.
So we say here to.
Minus the mean 1.7 quantity squared, and then multiply that by the probability 0.3.
And then the last one is this last value x can take on five minus the mean of 1.7.
We square that and multiply by the probability of a £5 package, 0.1.
Now if we do that math, one -1.7 is -0.7.
When we square that, we get positive 0.49 times 0.62 -1.7 is 0.3.
When we square that, we get 0.09.
So 0.09 times 0.3 and five -1.7 is 3.3.
When we square that, we get 10.8, nine times 0.1.
That's going to give us a value of 1.41.
And when we take the square root of that to get standard deviation, we find a value of approximately
1.19.
So that's our standard deviation for this discrete random variable x modeling the weight of the amount
of product we're shipping out.
But remember, the whole idea here is that we want to figure out how much money we're making when we're
getting paid per pound of product, but we're also sending the manufacturer $2 for every individual
package that they give us to ship.
So what we could do is we could set up a net gain equation, we'll call it here, capital N for net.
We'll think about this as profit or loss.
So net gain of our discrete random variable X and that's going to be equal to we'll write this as ten
X because remember X models the number of pounds, it models the weight in pounds.
So if X is pounds and we're getting paid $10 from the manufacturer to ship each pound, then the amount
of money that we're going to make is given by ten X, except that we then have to subtract two from
this net gain equation because we have to pay the manufacturer $2 for every product they give us.
So if we then take this net gain equation and we evaluate it at all of the values that X can take on
one, two and five we get when X is one, we get ten times one is ten, minus two is eight.
When x is two for a £2 package we get ten times two is 20, minus two is 18.
And for one of the £5 packages, when x is five, we get ten times five is 50, minus two is 48.
So what this is saying then is that our net profit is $8, our net gain is $8 for every £1 package that
we ship, which makes sense because it's a £1 package, the manufacturer is paying us $10 per pound
that we ship, which means that we're going to get ten bucks from the manufacturer for shipping that
£1 product.
But we also had to pay them $2 for that individual product.
So ten minus two, we get eight in contrast here, a £5 package because it's £5, they're paying us
$10 per pound.
We would make $50, except that for that one individual package, we paid them $2.
So instead of making $50, we make $48.
So now with these new values, we can set up a new probability distribution like we had over here instead
of X and the probability of X.
We'll look at this as N and the probability of N.
In other words, we can think about N as a new discrete random variable that has been scaled and shifted.
So the values that n can take on are 818 and 48 in the same way that X could take on the values of one,
two and five.
So we want to say here 818 and 48 and now we want to talk about the probability of each of these dollar
amounts.
And of course those probabilities are still going to be the same.
The manufacturer is sending us product.
60% of that product is still these £1 packages.
So there's a 60% chance that we make $8.
There's a 30% chance that we make $18 and a 10% chance that we make $48.
So now if we want to find the mean and standard deviation of this new discrete random variable n we
could of course, do the same thing we did before and use this distribution table to calculate the expected
value and the standard deviation from scratch.
Or we could use what we just learned about transforming random variables by shifting and scaling to
just transform the mean and standard deviation we already calculated so.
If you remember, we said that the mean was affected by shifting and it was also affected by scaling.
What we can do then is say that our new mean.
So instead of mu sub x, which represents the mean of the original discrete random variable, x will
say that mu sub n the mean representing this new discrete random variable n has to be equal to remember
we set up this equation for n in terms of x, so instead of ten times x minus two, we'll say ten times
the original mean.
So mu sub x and then minus two.
And we include the ten and we include the minus two because the mean is affected by the scaling of ten
and also by the shifting of two.
So we can just plug 1.7.
Into this equation and we get 17 minus two or 15.
So the new mean, the mean here for this data distribution is 15.
And of course we would find that same value if we used this same calculation we did before, where we
take eight and multiply it by 0.6 plus 18 times 0.3 plus 48 times 0.1.
So we could have calculated it that way.
But instead of going through all that math, we can just scale and shift the mean we already found since
n is just a shifted and scaled version of the original variable X.
And then the same thing goes for the standard deviation.
Except remember that standard deviation is only affected by scaling.
It's not affected by shifting.
So the standard deviation of this new discrete random variable n instead of plugging it in here to ten
x minus two and replacing x with the standard deviation of x to say ten times the standard deviation
of x minus two, we will ignore the minus two because the standard deviation isn't going to be affected
by this shift of minus two.
So the new standard deviation is simply ten times the old standard deviation.
With respect to X, we know that that was 1.19, so this is approximately equal to ten times 1.19 or
about 11.9.
And of course, just like before, we could have found that the old fashioned way, we could have said
here our data point eight minus the mean that we calculated 15 quantity squared times the probability
of that particular value eight and then plus 18.
Minus the mean of 15, square it, multiply it by the probability.
And then the last one here, 48.
Minus the mean of 15.
Square it and multiply it by the probability.
We could have done that whole calculation to get variance and then taking the square root of that variance
to get standard deviation.
And we would have found the same value here of approximately 11.9.
But there's no need to go through all that work since n is just a data set under transformation by shifting
and scaling from this original data set X.
So whereas X modeled the weight that we were shipping out and models the amount of money that we make
for doing that shipping and these values we calculate it for X tells us that on average the mean weight
of each package that we ship is £1.7 with a standard deviation of £1.19.
And then with that we can say that the mean amount of money we make for every package we ship out,
we make on average a mean of $15.
Even though for any given package, we will only ever make either $8 or $18 or $48 with no values in
between.
Our profit will only ever be one of these three values for an individual package.
But when we take the mean there, when we look at the long term average, based on the fact that 60%
of the packages we ship net us $8, that 30% of the packages we ship net US $18, and that 10% of the
packages we ship net US $48.
The mean amount of profit per package is $15 with a standard deviation of just under $12.
And we were able to get all of this information here about the amount of money we make modeled by DN,
Just by applying a scale and a shift to this X variable we already have.
Instead of collecting all new data about the profit per packages and the probability of each of these
amounts of profits and then calculating from scratch this mean here and this variance here, and then
therefore standard deviation.
So you can see how understanding this transformation of random variables by scaling and shifting can
save us a lot of time answering real world questions.