<< Chapter < Page Chapter >> Page >

The method of least squares

We now come to a more accurate method of finding the line of best-fit. The method is very simple. Suppose we guess a line of best-fit. Then at at every data point, we find the distance between the data point and the line. If the line fitted the data perfectly, this distance should be zero for all the data points. The worse the fit, the larger the differences. We then square each of these distances, and add them all together.

The best-fit line is then the line that minimises the sum of the squared distances.

Suppose we have a data set of n points { ( x 1 ; y 1 ) , ( x 2 ; y 2 ) , ... , ( x n , y n ) } . We also have a line f ( x ) = m x + c that we are trying to fit to the data. The distance between the first data point and the line, for example, is

distance = y 1 - f ( x ) = y 1 - ( m x + c )

We now square each of these distances and add them together. Lets call this sum S ( m , c ) . Then we have that

S ( m , c ) = ( y 1 - f ( x 1 ) ) 2 + ( y 2 - f ( x 2 ) ) 2 + ... + ( y n - f ( x n ) ) 2 = i = 1 n ( y i - f ( x i ) ) 2

Thus our problem is to find the value of m and c such that S ( m , c ) is minimised. Let us call these minimising values m 0 and c 0 . Then the line of best-fit is f ( x ) = m 0 x + c 0 . We can find m 0 and c 0 using calculus, but it is tricky, and we will just give you the result, which is that

m 0 = n i = 1 n x i y i - i = 1 n x i i = 1 n y i n i = 1 n ( x i ) 2 - i = 1 n x i 2 c 0 = 1 n i = 1 n y i - m 0 n i = 0 n x i = y ¯ - m 0 x ¯

Khan academy video on regression - 1

In the table below, we have the records of the maintenance costs in Rands, compared with the age of the appliance in months. We have data for 5 appliances.

appliance 1 2 3 4 5
age ( x ) 5 10 15 20 30
cost ( y ) 90 140 250 300 380

Find the line of best fit using the method of least squares.

  1. appliance x y x y x 2
    1 5 90 450 25
    2 10 140 1400 100
    3 15 250 3750 225
    4 20 300 6000 400
    5 30 380 11400 900
    Total 80 1160 23000 1650
  2. m 0 = n x y - x y n x 2 - x 2 = 5 × 23000 - 80 × 1160 5 × 1650 - 80 2 = 12 c 0 = y ¯ - b x ¯ = 1160 5 - 12 × 80 5 = 40 y ^ = 40 + 12 x ̲

Using a calculator

Find a regression equation for the following data:

Days ( x ) 1 2 3 4 5
Growth in m ( y ) 1,00 2,50 2,75 3,00 3,50
  1. Using your calculator, change the mode from normal to “Stat x y ”. This mode enables you to type in bivariate data.

  2. Key in the data as follows:

    1 ( x , y ) 1 DATA n = 1
    2 ( x , y ) 2,5 DATA n = 2
    3 ( x , y ) 2,75 DATA n = 3
    4 ( x , y ) 3,0 DATA n = 4
    5 ( x , y ) 3,5 DATA n = 5
  3. Ask for the values of the regression coefficients a and b .

    RCL a gives a = 0,9
    RCL b gives b = 0,55
    y ^ = 0 , 9 + 0 , 55 x

Using a calculator determine the least squares line of best fit for the following data set of marks.

Learner 1 2 3 4 5
Chemistry (%) 52 55 86 71 45
Accounting (%) 48 64 95 79 50

For a Chemistry mark of 65%, what mark does the least squares line predict for Accounting?

  1. Switch on the calculator. Press [MODE] and then select STAT by pressing [2]. The following screen will appear:

    1 1-VAR 2 A + BX
    3 _ + CX 2 4 ln X
    5 e ^ X 6 A . B ^ X
    7 A . X ^ B 8 1/X

    Now press [2] for linear regression. Your screen should look something like this:

    x y
    1
    2
    3
  2. Press [52] and then [=]to enter the first mark under x . Then enter the other values, in the same way, for the x -variable (the Chemistry marks) in the order in which they are given in the data set. Then move the cursor across and up and enter 48 under y opposite 52 in the x -column. Continue to enter the other y -values (the Accounting marks) in order so that they pair off correctly with the corresponding x -values.

    x y
    1 52
    2 55
    3

    Then press [AC]. The screen clears but the data remains stored.

    1: Type 2: Data
    3: Edit 4: Sum
    5: Var 6: MinMax
    7: Reg

    Now press [SHIFT][1]to get the stats computations screen shown below. Choose Regression by pressing [7].

    1: A 2: B
    3: r 4: x ^
    5: y ^
    1. Press [1] and [=]to get the value of the y -intercept, a = - 5 , 065 . . = - 5 , 07 (to 2 d.p.) Finally, to get the slope, use the following key sequence: [SHIFT][1][7][2][=]. The calculator gives b = 1 , 169 . . = 1 , 17 (to 2 d.p.) The equation of the line of regression is thus: y ^ = - 5 , 07 + 1 , 17 x
    2. Press [AC][65][SHIFT][1][7][5][=] This gives a (predicted) Accounting mark of ^ = 70 , 94 = 71 %

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Siyavula textbooks: grade 12 maths. OpenStax CNX. Aug 03, 2011 Download for free at http://cnx.org/content/col11242/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Siyavula textbooks: grade 12 maths' conversation and receive update notifications?

Ask