Create a MATLAB program to obtain the coefficients of a linear regression task using the least- squares. The following table contains the data that you are going to use for this task: x y -3 -4.0756 -2.3333 -4.7784 -1.6666 -3.1615 -1 -2.1729 -0.3333 1.2987 0.3333 0.3348 1 5.2448 1.6666 4.2721 2.3333 6.8857 3 7.8506 Table 1: Test case for Task 2. The linear regression coefficients $m$ (slope), $c$ (intercept) and $R$ coefficient can be computed according to: $m = \frac{N\sum(x_iy_i) - \sum x_i\sum y_i}{N\sum x_i^2 - (\sum x_i)^2}$ $c = \frac{\sum y_i - m\sum x_i}{N}$ $R = \frac{N\sum x_iy_i - \sum x_i\sum y_i}{\sqrt{[N\sum x_i^2 - (\sum x_i)^2][N\sum y_i^2 - (\sum y_i)^2]}}$ Report the $m$, $c$ and $R$ values. Additionally, create a single plot that shows the data points and the curve obtained with the linear regression method.
Added by Robert T.
Close
Step 1
We are given the following data: x = [-3, -2.3333, -1.6666, -1, -0.3333, 0.3333, 1, 1.6666, 2.3333, 3] y = [-4.0756, -4.7784, -3.1615, -2.1729, 1.2987, 0.3348, 5.2448, 4.2721, 6.8857, 7.8506] Show more…
Show all steps
Your feedback will help us improve your experience
Sri K and 76 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Use least squares regression to fit polynomials of order 1, 3, and 5 to the data given in the table. Compute the correlation coefficient for each fit (Use Gauss elimination with partial pivoting in the solution of linear equation systems). Plot 1st, 3rd, and 5th order polynomial fits and the given discrete data. Comment on which of these curves explains the variability of the given data better.
Sri K.
To find the least squares regression line $y=a x+b$ for a set of points $$\left(x_{1}, y_{1}\right),\left(x_{2}, y_{2}\right), \ldots,\left(x_{n}, y_{n}\right)$$ you can solve the following system for a and $b$. $$\left\{\begin{aligned}n b+\left(\sum_{i=1}^{n} x_{i}\right) a &=\left(\sum_{i=1}^{n} y_{i}\right) \\ \left(\sum_{i=1}^{n} x_{i}\right) b+\left(\sum_{i=1}^{n} x_{i}^{2}\right) a &=\left(\sum_{i=1}^{n} x_{i j}\right)\end{aligned}\right.$$ The sums have been evaluated. Solve the given system for $a$ and $b$ to find the least squares regression line for the points. Use a graphing utility to confirm the results. $$\left\{\begin{aligned} 7 b+21 a &=13.1 \\ 21 b+91 a &=-2.8 \end{aligned}\right.$$
Linear Systems and Matrices
Systems of Linear Equations in Two Variables
To find the least squares regression line $y=a x+b$ for a set of points $$\left(x_{1}, y_{1}\right),\left(x_{2}, y_{2}\right), \ldots,\left(x_{n}, y_{n}\right)$$ you can solve the following system for a and $b$. $$\left\{\begin{aligned}n b+\left(\sum_{i=1}^{n} x_{i}\right) a &=\left(\sum_{i=1}^{n} y_{i}\right) \\ \left(\sum_{i=1}^{n} x_{i}\right) b+\left(\sum_{i=1}^{n} x_{i}^{2}\right) a &=\left(\sum_{i=1}^{n} x_{i j}\right)\end{aligned}\right.$$ The sums have been evaluated. Solve the given system for $a$ and $b$ to find the least squares regression line for the points. Use a graphing utility to confirm the results. $$\left\{\begin{aligned} 5 b+10 a &=11.7 \\ 10 b+30 a &=25.6 \end{aligned}\right.$$
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD