Lesson goal: Computing a trendline

Previous: Guess your own trendline | Home | Next: Compute the r-value for a trendline

In the last lesson we guessed at a trendline for some data points. Here, let's rigorously compute the best possible trendline.

It turns out that it's mathematically possible to solve for the slope $m$ and y-intercept $b$, that forms the best possible trendline for some data points. (How this actually works is beyond our scope here, but in short, if one minimizes the vertical distance between each data point and the trendline, the following equations will result.)

To start, you'll need a parameter called $c$ which is $$c=N\Sigma x_i^2 - (\Sigma x_i)^2.$$ Here $N$ is the number of data points you have (6 here) and $x_i$ is the $i^{th}$ data point. So, $\Sigma x_i^2$ means to take each x-axis data point one by one, square it, then add all of the squared data points together. Similarly, $(\Sigma x_i)^2$ means to add all x-axis data points together, then square the whole sum.

Next, we can compute the slope for the best trendline from this equation: $$m=\frac{N\Sigma x_i y_i-\Sigma x_i \Sigma y_i}{c}.$$ The y-intercept comes from: $$b=\frac{\Sigma x_i^2 \Sigma y_i - \Sigma x_i \Sigma x_i y_i}{c}.$$

Now you try. Fill in the ?? spots to allow for computing a slope and y-intercept to the best possible trendline through the data points.

Type your code here:

See your results here: