With no shortage of wearable fitness trackers and health apps out there,
serious and not-so-serious runners alike can capture every speck of data on their workouts;
from heart rates to exact GPS coordinates.
With all that knowledge just a click away, it should be easy to stay up on your progress.
But when you feel strong running one day, and you're out of breath another day… the
data might be all over the place.
So how do you know if you're improving and you’ll be able to finish your 10k goal?
We’ve explored graphs as a way to visualize data and learn more about relationships between
variables from the shape of a curve.
But real-world data is noisy and imperfect.
If we try to plot your fitness data as points on a graph,
they'll never fall neatly into a line or curve we can describe exactly with an equation.
Today, we’ll combine our linear and quadratic graphing skills to find meaning in these messes
of data because all data can still tell us something.
G’Day, I’m James Tanton, and this is Study Hall Algebra, presented by Arizona State University
and Crash Course.
We can’t get a sense of the shape of a line or curve without plotting enough data points.
For instance, let’s say we want to find an equation that fits this data.
One point: total mystery. Two points: that might be a line.
Three, four, five points -- well, it doesn’t look like a line right now -- maybe a circle?
Or a loop-di-loop? We still don’t know.
But seventy-six points? Ahhh. A parabola. Or at least some kind of U-shaped curve.
When we gather data from an equation already given to us, our points will certainly line
up perfectly on a curve.
But data that comes from the real world doesn't come equipped with an equation.
It tends to look like a handful of dried beans scattered across the page.
So when we plot the points, it makes sense that the picture we get is called a scatter
plot,
or a graph that’s just a collection of points on the Cartesian plane with no curve connecting them.
But if the data points on our scatter plot resemble some sort of shape like a line or
something curvy,
there’s likely a correlation, or a relationship between the inputs and outputs.
In fact, there might be an equation that describes that correlation, and trying to write it down
is called fitting an equation.
Of course there are a myriad of different possible equations out there.
But in science and the rest of life, there are a surprising number of linear correlations,
which are relationships between two variables that look like a straight line when plotted.
So let's start there.
If our plot of data looks like it’s kinda following a straight line and we suspect a
linear correlation,
we want to find a line of best fit, or a straight line that best represents the trend in the data.
Using data to estimate that line is called a linear regression.
“Linear” because we’re finding a straight line, and “regression” because we’re looking
back at the data we have and fitting an equation to it retroactively.
You might see this done in your statistics class rather than your algebra class.
Linear regression combines two of college algebra’s greatest hits:
solving linear and quadratic equations.
We can give linear regression a try with these three points. But to find a more accurate
trend, we’d really want way more points -- at least 30.
Our challenge is to draw the line that mimics the data “the best.”
For us, that means we want to find a line that’s as close to every data point as possible
using something called linear least-squares regression. What a fancy name!
We can start where any good story begins: the...middle!
If we average the x-values, we get 2. And if we average the y-values, we get 3.
Stick those values together and the point we get is the center of our data points: (2,3).
We want our line to cut through this central point.
Next, we need to find the slope of the line through that point.
Let's plug (2,3) into our slope equation, which we can rewrite as y = m(x-2) +3.
Now we have an equation for a line with a mystery slope that runs through (2,3), and
we can add a new column to our data table.
We'll plug the x values we have into our equation to get some predictions for y-values.
Sure, we don’t know what the slope is yet, but we can carry “m” through as a stand-in.
We can look at how far off our predictions are from the actual values by finding the deviations,
or the differences between the actual values and the predicted values.
Now, some predictions will be too high, and some will be too low.
So we’ll have a mix of positive and negative deviations.
One way to make things simpler (and make sure we're only dealing with positive numbers)
is to square each deviation.
So there’s where the name “least-squares” comes from!
If we add up all the squared deviations, we get the quadratic expression 2m^2 - 6m +6
with “m” -- the slope -- as the input variable.
I know, it's not the "x" we're used to, but we can handle it just the same!
If we find the minimum of this equation, we’ll find the slope that makes the squared deviations
the smallest. Bingo!
Fortunately, our first coefficient is positive 2, so the graph of this parabola y=2m^2-6m+6
will be facing up, and the vertex of this equation will be the minimum.
Now, we can rewrite this in the form 2m(m-3) + 6 and see that the minimum occurs for m = 3/2.
That means the slope of our linear least-squares regression equation will be 3/2.
So our line of best fit is y = 3/2(x-2)+3. If we graph it next to our original data points,
we can see that it mostly follows them. That's the best we can do!
Alright. Let’s see how fitting an equation to data has changed throughout history.
The ink may have faded, the handwriting may be a little strange,
but through the Regression Lens on the Math Goggles, we can see data just anywhere.
Oh my goodness, the example I wanted!
If you’ve ever been out in the country on a warm night, you’ve probably heard a lot of crickets chirping.
In fact, there’s an old wives tale that says crickets chirp more often on hot nights.
And in 19th-century America, a few people tried to prove it -- and found out those old wives were actually right.
Amos Dolbear gets most of the credit these days after publishing a formula for
“The Cricket as a Thermometer” in 1897.
He proposed the temperature outside, measured in degrees Fahrenheit equals 0.25 times the number of
chirps per minute, plus 40.
But Dolbear didn’t share the data he used, or how he got his equation –
which means he wouldn’t get published today, since showing your work is fundamental to modern science.
But Margarette Brooks, who published the “Influence of Temperature on the Chirp of the Cricket”
in a popular science magazine 16 years earlier, did show her work. Brooks was testing the formula
proposed by someone known only as WGB, using this real cricket data.
Apparently cricket-chirping was a hot topic in the late 1800s!
Now, we can find the line of best fit for this data with our least squares method.
It gives T=0.2519N + 40.53.
We could do that by hand now that we know how it works, but it's actually much easier and faster
to just use a simple computer program.
So who was closer? If we put in a sample input of a hundred chirps per minute,
Dolbear’s method says it’s 65 degrees outside in Fahrenheit.
And the formula Brooks was testing says it’s 67 degrees.
And the line of best fit and the predictive power of math gives us…approximately 66 degrees.
Pretty darn impressive all around -- especially since both stopwatches and linear regression
had only recently arrived in the 19th century,
and we don’t know whether either Brooks or Dolbear had access to those newfangled technologies.
So we can use our lines of best fit to make predictions, like we did here -- but as always,
extrapolation is perilous.
We want to be careful about relying on projections for the absolute truth.
Our cricket equation for instance, might tell us that it's several hundred degrees Fahrenheit
outside if we heard thousands of chirps.
And that’s not very helpful.
It could be that we’ve found a line, but it doesn’t actually fit the data very well.
To estimate how good our model is, we calculate the coefficient of determination, sometimes
called the r^2 value, which measures how the differences in the y-values
can be explained by the differences in the x-values.
Any linear regression program will automatically include r^2, though we can actually find it
by hand with a bit more algebra.
To learn more, check out Crash Course Statistics!
Ideally, r^2 should be as close to 1 as possible.
But with real-world data, an r^2 of 0.85 or higher is considered pretty good.
For the crickets, our line has an r^2 of 0.973. Wow!
But data can take lots of shapes, not just straight lines.
A quick test to see if your data really is linear is to find the correlation coefficient,
which measures the strength and direction of the linear relationship between two variables.
The correlation coefficient is denoted by “r” or “rho,” and can range between -1 and 1,
with bigger numbers meaning stronger correlations.
That’s the same r as in r^2, so if it squares to 1, we’ve got a perfect linear fit.
So if "r" seems a bit low or the shape of the data is somewhat curved,
we might actually be dealing with an exponential or quadratic correlation, not a linear one.
But we might be able to use the same tools to find the equations of non-linear data,
if we make some clever transformations.
For example, suppose we think a data is following an equation of the form
y = c * a^x -- an exponential relationship.
We can take the logarithm of both sides to get log y = x log c + log a.
The equivalent equation might look a little weird, but if we squint a little, it kind of looks like
a linear equation with x and log y as the variables.
Everything else is just a number.
Or if we think we have a quadratic function like y = ax^2 hiding in the data,
we can square-root both sides and plot the relationship between √ y and x.
The trick here is to think about how we can transform the data to sort of “flatten”
the correlation we’re seeing,
and then we can use linear regression again!
So even in data science, algebra is the foundation we need to keep exploring.
So keep honing your algebra skills. But when you encounter data in the wild, here are some tips.
If you have any control over the dataset you’re working with,
collect as many points as possible so that you have the best chance
of revealing the “true” shape of an equation that might be behind the data.
The line of best fit of a data set always passes through the heart of the data –
use it to fit your curve.
And if you have a logarithmic, exponential, or polynomial relationship in your data,
you might still be able to use linear regression – you just need to reframe the relationship
between x and y.
Make it a linear one between log(y) and x, or between sqrt(y) and x, or whatever works
for your relationship.
Phew! We've done a lot. In fact, our next episode is our last episode.
So next time we’ll go over a sneaky topic we've been secretly side-stepping all this time:
the role of zero in algebra.
It’s actually tricky! And we’ll even get a preview of calculus. Until then, cheers!
Thanks for watching Study Hall Algebra, which is produced by Arizona State University and
the Crash Course team at Complexly.
If you liked this video and want to keep learning with us here at Study Hall, be sure to subscribe.
You can learn more about ASU and the videos produced by Crash Course in the links in the description.
See you next time!