Linear regression is a method for calculating the equation


Linear regression is a method for calculating the equation of the "best" straight line that passes through a set of points. By "best," we mean the "best fit" straight line—the one that passes as closely as possible to as many points as possible. To calculate the equation of this best fit straight line, you begin with a set of N data points, y;), for i = 0,1, 2, 3....., N — 1. You then calculate: Sum of Sum of 

Sum of squares of 

Yi Sum of products of x,y,: sP-1 

E"n E x‘Y‘ The equation of the "best fit" straight line b will then have slope m given by 

And y-intercept b as: 

b= 

M = 

— 

(Y-)(.')-(")(2 xtYll N — x,) 

However, a linear regression is only as good as its fit. While it is not the best goodness-of-fit test for a linear regression, the le value is commonly accepted as a decent enough indicator of how well a line fits the data it is supposed to represent. Commonly, an le value of .9 or higher is considered a good fit. Anything below .6 is considered inconsequential, and anything in between ranks from mediocre to decent. The le value can be calculated as shown below. 

where, y 

The difference between )7 (the value or y as estimated by the line) and y (the original data value) should be noted. 

Your program should: 

• Read two sets of data from a file (11W7dateMB and store them as arrays of length 20. The data is presented as x y form (on each line there will be a value for and a value for y) where isod  an integer and y is a float value. Continue reading the file and allocating the data into two arrays. The data file is located in the Documents section on Blackboard. • Find the estimated slope, m. • Find the estimated intercept, b. • Find the 12' value for the line created using the previously found estimated slope and intercept. • Output the equation of the line as well as Melt.' value onto thc screen. 

Notes: 

• Ideally the user should ace very little on the screen and have no input at all. • You will probably need more than the two originally defined arrays. However, recognize that SUMS and meant are only net value and therefore do not need to be stored as arrays. • It may help to break up calculations into numerators and denominators as well • To read the values from HW7datamt, use the following code fragment. 

int x[20]; float y[20]; FILE app; fp = fopen("HW7datuter,Y); for(i=0; i<20; t-m) 

MeauF(FIVYul %Di 804ili &Yli1); //Reads new linc from Elk every time the Rop executes 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Linear regression is a method for calculating the equation
Reference No:- TGS01146848

Expected delivery within 24 Hours