The first kind of plot we want to talk about is the scatterplot also called a scatter graph or scatter
chart, which shows the relationship between two dimensions or characteristics or measurements of a
group.
So as we walk through this idea, let's just take a set of data.
Let's say we're running a small business here and we ship out products to customers as they order them
from our website.
And maybe we keep track of lots of different pieces of data about our shipments.
And let's say this is just a snapshot here of some of that data.
So we record this state that we're shipping to.
We categorize those states by regions.
So we group states into the West, Midwest, Southeast, northeast, etc. regions.
And then we also record the number of items we send in each shipment.
So for this first order here in this first row, the person ordered three items.
So the item count is three.
Their order total is $2.08.
So they bought three very inexpensive items.
And with just that data alone, we can create a scatterplot that compares the number of items sent and
the order total, the total amount of money for that item count.
So here's what that scatterplot might look like if we put item count along the horizontal axis here.
So all the way from zero items up to ten items, we can see in our data here that the most items we've
recorded for any shipment is ten items, and then we place order total along the vertical axis here.
So starting at zero along the bottom up to $100.
So item count here is a number order total is in dollars and we can see here if we skim through order
total that in fact this data is sorted by order total from smallest to largest order with the most expensive
order being $99.69, which is why this vertical axis spans from $0 to $100.
And then if we plot each order as a data point, what we create is a scatterplot.
So taking this first order here, the customer ordered three items and the order total was $2.08.
So we could think about along the horizontal axis here, locating three items.
If this is two items and this is four items, then three items should be about halfway between.
And then if this is $0 and this is $20, then $2.08 should be very close to the bottom of our vertical
axis here, very close to $0.
And in fact, we see that data point right there.
That is the data point for this first order.
And we could take any other order in our data set here and locate its point on the scatter graph.
For instance here, this order that got sent to Georgia, the person ordered nine items and spent $45.24.
So nine items should be right about halfway between eight and ten.
And if we go up to 45, 24, if this is $40 and $60, $50 should be right about here.
$45 should be right about here.
It looks like this is the point associated with that order of nine items for a total of $45.24.
So all of these orders have been plotted as individual points in this scatterplot.
Now, a couple of things we really want to remember as we're creating scatter plots.
The first is the most general point that what we're doing here is essentially comparing two characteristics
of the same variable, if you will.
So here in this particular example, we're comparing item count and order total for individual orders.
And we could just as easily compare different characteristics of the same set of orders.
For instance, maybe we also keep track of the time of day when the order was placed.
We could make a different scatterplot that shows time of day along the horizontal axis and item count
along the vertical axis or time of day along the horizontal axis and order total along the vertical
axis, regardless of which two characteristics we pick about our variable.
When we create a scatterplot, we want to if we can think about putting the independent variable along
the horizontal axis and the dependent variable along the vertical axis.
Now that's not going to be a perfect science because there may not be direct causation between the two
characteristics that we're comparing.
But if we can think about in general one characteristic causing the other, we want to put the characteristic
that initiates the cause along the horizontal axis and the outcome or the cause along the vertical axis.
So an easy example might be height versus weight of people.
So if we think about.
Height.
Versus.
Wait.
This is a good example because it reveals the shortcomings of this idea.
But in general, we have some intuition that the taller someone is, the more they're going to weigh.
Of course, that's a very broad generalization.
We often see taller people who weigh less than shorter people or shorter people who weigh more than
taller people.
So obviously, there's not perfect causation here.
Being taller doesn't necessarily mean that you will be heavier, but it probably does make a little
more sense to put height along the horizontal axis.
Because in general, as a very broad idea as height increases, weight is probably likely to increase.
So height is cause weight is the effect or the outcome.
Now, oftentimes if we switch these so if we were to put weight along the horizontal axis and height
along the vertical axis, it's usually not going to cause a big problem.
Same thing with this example here.
We could flip item count and order total putting item count along the vertical axis in order total along
the horizontal axis, and we'd still be able to do the math that explores this relationship.
Same with height and weight.
But if possible, if we can somewhat identify that a height increase tends to cause a weight increase,
we would put height along the horizontal axis, weight along the vertical axis in the same way that
maybe in general as item count increases or total increases.
We like to generally put that independent variable along the horizontal axis and the dependent variable
along the vertical axis.
But again, this is not a perfect science and switching these two isn't usually going to cause us trouble.
We also want to say along these lines that saying we've heard before that.
Correlation.
Does not necessarily equal.
Causation.
So just because weight tends to increase as height increases doesn't mean that height perfectly dictates
weight or just because order total tends to increase as item count increases doesn't mean that increasing
the item count is guaranteed to increase the order total.
Two things can be correlated, meaning that they can increase together or they can decrease together,
or they can move in opposite directions.
But the relationship between the two characteristics, the correlation between the two characteristics
doesn't necessarily mean that a change in one characteristic is actually the cause for the change.
In the other characteristic, there could be some third confounding variable or some other outside force
that's causing the correlation between the two characteristics or the correlation we're seeing might
just be coincidental.
There's no guarantee necessarily of causation.
And so we need to be really careful that just because we plot our data on a scatterplot and maybe we
see some general trend does not prove that we somehow have causation between the two characteristics.
All we can really say is that we see some kind of a trend in the data.
In this case, the example we're using, it appears as though as item count increases, order, total
increases or as order total increases, item count increases because that's the direction we're seeing
in this trend line that we've plotted.
Now, that being said, let's talk about this trend line a little more.
We call this when we're dealing with a scatterplot, we call this the trend line, sometimes the regression
line, the best fit line line of best fit, even the least squares line, those are all basically names
for the same thing, which is this line that indicates the trend through the data.
And we actually have mathematical formulas for calculating this line.
Now, we can do this by hand with this set of formulas here, but of course it's going to be much easier
for us to plug our data into a calculator or software and have it calculate the equation of this trend
line for us.
But even if we do that, these are the formulas that our software or our calculator will use to find
the equation of this line.
Now, if you've ever taken algebra, you know that the equation of a line is given by Y equals m, x
plus B.
Now M, this value here in front of the X is the slope of the line.
It tells us the rate at which the line is increasing or decreasing.
So a higher value for M means the line is steeper, it's increasing faster, whereas a lower value for
M means the line is more shallow, it's increasing more slowly.
A negative value for M indicates that the trend is decreasing.
The line would be going in the opposite direction this way, this value.
B Here is the point at which the line intersects the vertical axis.
So if we picture here this vertical axis, then it b is this value right here.
So in our case it looks like B is a little less than ten because we have here zero and 20 along the
vertical axis, this looks like it's a little less than half way from 0 to 20.
So I'm guessing that the value of B is a little less than ten, and we'll actually calculate this value
to find out.
So if we have the slope and we have the y intercept, then we can plug in any value of x and this equation
will return to us a value for y.
So while this formula is normally in algebra, just y equals mx x plus B, this little hat on the Y,
we call this y hat.
This indicates that we're talking specifically about a trend line and we want to distinguish between
the equation of a trend line and the equation of just a regular line, because we want to be super aware
of the fact that the equation of the trend line is sort of this predictive trend.
And what we notice here, if we look at this trend line, is that it actually doesn't pass through a
single point in our data set, right?
We plotted all these points.
This little point down here was the 0.3 $2.08.
This point right here was the 0.9 and $45.24.
This line is supposed to predict the value for order total when we pick a particular value for item
count.
So what this trend line is really saying is that let's say we consider an item count of eight.
If we come here to item count of eight, we come straight up from the horizontal axis until we meet
the trend line and then we head straight over to the vertical axis.
From that point it looks like we get to a value here of maybe roughly 65, let's say.
If that's the case, then what this trend line is telling us is that the expected order total for an
order with eight items is about $65.
But of course, if we look at our raw data, we don't see any.
Orders where the item count is eight and the total is $65.
In fact, if we scan through here, the only time where we have an item count of eight is these three
orders right here.
And we can see that the order total for each of those is over $95 each time.
In fact, we see those three data points right here, and those values aren't anywhere close to $65.
We can also scan through this list and see orders that have a total near $65.
What we find is that the closest two orders are these right here where the totals were $58.37 and $70.01
and the item counts.
There were ten and six items respectively, not eight items.
So what we need to realize is that the trend line is not predictive at all in terms of actual specific
data values in our data set.
What it does instead is compute what it believes are the expected values for order total based on item
count or vice versa, and gives us a trend line that is the most efficient path through the data, which
means that if we're trying to make real world decisions using a trend line, we need to be really careful
because this gives us a guideline that we can use to estimate what we might see.
Of course, using this example, we know that the trend line estimates that if someone orders eight
items, we can probably expect that order to be around $65 on average.
But as we can see from our data, we are certainly not guaranteed that exact order total if we pick
an eight item order.
So we can somewhat use this trend line through a scatterplot to make predictions.
But we just have to be aware of the fact that it's only an expected value.
It's only an average for order total based on item count.
It's not perfectly predictive of all of the orders will get.
If it was perfectly predictive, then every single dot in our scatterplot would be exactly along this
line.
So that being said, let's just walk through this math using the table we've created here so that we
can see how to calculate M and B, and then use this equation to plot the trend line.
So if we have our raw data here, we need a few things.
We need the value of N, which is the count of data points in our set.
Here we have 25 orders if we count here, the number of rows we have, we have 25 orders.
We've indicated that here.
So when our case end is equal to 25.
So let's look at what this looks like to plug everything in here.
We'll get 25.
Then we multiply that by the sum of all of the products of X and Y.
So we're going to say here that item count represents X and that order total represents Y, which makes
sense because we put item count along the horizontal axis, which is the x axis, and we put order total
along the vertical axis, which is the Y axis.
So what we're doing here with this sum of all the products of X and Y is we're multiplying X by Y for
every order.
So we're multiplying item count and order total for each order.
And we see that here in this column, the product of count and order, total item count and order total.
So if we multiply three by $2.08, we get $6.24 or just 6.24 without the units of dollars.
If we multiply six by five, we get 30.
If we multiply one by 9.65, we get 9.65.
So we're just multiplying X and Y or these two values to get the product.
Then this here, the sum of all the products means we take all these products and we sum them, we add
them together.
And if we sum all of these values, we get 88 6.38.
So we multiply this by 80 806.38.
Then we'll subtract the sum of all of the x values.
So we've said x is item count.
If we sum all of these item counts, we get a sum of 138 right here.
So 138 multiplied by the sum of all the y's well y is order total.
So if we sum all of these order totals, we get a sum of 1,229.38.
So we multiply this by 12 29.38, and then we divide by n, which we already said was the count of orders
25 multiplied by the sum of all of the x squared values.
In other words, X is item count.
So we want to take every item count and square it.
So we take three, we square it, we get nine.
That's this column here, count squared, we take six, we square it and we get 36 one.
Word is one zero squared is zero, four squared is 16.
So we square all of the X's and once we've squared them all, we add them together and the total is
1038.
That is the sum of all the x squared.
So we multiply by 1038 and then we subtract from this the sum of all the X's.
And once we get the sum of all the X's, then we square that value.
Well, the sum of all the X's we already found, we take all the X's, we add them together, we get
138.
So that is the sum of all the X's.
But then we square that.
So we're taking 138 and squaring it.
And here's the sum squared value 138 squared is 19,044.
So we're subtracting 19,000.
44.
And if we use a calculator to do the math here, what we get is approximately 7.3132.
When we round a four decimal places, that's the value of M, That is the slope of the trend line,
which means that for every one unit we move to the right along the horizontal axis will move up about
7.3 units along the vertical axis, meaning that for every one item we add to item count, we increase
order total by about $7.31.
That's what that slope is telling us.
Now all we have to do is calculate B using this formula, and when we do, we get the sum of all the
y's, which we know is 12 2938 So we get 1229.
38.
And then we subtract.
We use the value of em that we just calculated.
So M is about 7.3132.
So we say 7.3132, and then we multiply that by the sum of the x's, which we know is 138, so 138.
And then we divide this whole thing by the number of orders and equals 25, so we divide by 25.
And the result there is approximately 8.8063 when we round to four decimal places, which means that
the equation of our trend line using this formula here is y hat approximately equal to 7.3132 times
x plus 8.8063.
Now, we've already plotted the trend line here, but if we wanted to use this equation to plot it because
let's say we didn't have it yet, we just had the scatterplot and now we want to sketch in this trend
line what we would do.
Remember that B here is the y intercept.
This is the value where the trend line intersects the Y axis.
So we would come here along the y axis, the vertical axis, and we would locate about 8.8, and that's
this value we saw earlier.
It's about 8.8.
Remember before we said we thought it was a little less than ten?
Well, it's about 8.8.
So we would start there with this point.
We'd put a point there along the axis and then this slope here of 7.313, two tells us, like we said
before, that for every one unit we move over along the horizontal axis, we move up seven units along
the vertical axis, which means that when we move out to X equals one from 8.8, we should go up about
7.3.
So at x equals one, we should get about 8.8 plus 7.3 is 16.1.
So we would come up and we would locate about 16.
Point one right about here.
We could see that that's maybe at 16 here along the vertical axis.
Then we would move over one more unit to X equals two and we would move up another 7.3.
So from 16.1, adding 7.3, again we get about 23.4 and we can see here at two a value of about 23.4.
So you can see that line starting to sketch out.
That's how to do it by hand.
Of course, if we just plug this line into any graphing calculator, computer algebra system or software
program, it will plot this line for us without us having to find points to plot it out manually.
But once we have even just two points, then we can sketch in a line that passes through those two points
and we see that we get the trend line.
Now we'll talk much more about scatter plots and trend lines when we talk later in the course about
regression.
But this is the general idea behind using a set of raw data to create a scatterplot.
How we can read and interpret a scatterplot, and then how to use these formulas to actually build the
equation of the trend line that runs through the data in our plot.