Least Square Fitting & Regression

When you try to fit a line to a number of points, you add the distances from the points to the line and minimize the sum of the squares of the distances. In mathematics the distance between a point and a line is defined as the shortest distant, i.e. the perpendicular distance. When you do numerical calculations however, there are various ways of defining the distance.

Perpendicular fitting

The segments are perpendicular to the red line. Move the line and try to get an optimal fitting. The line is optimal when the sum of the squares is minimized. Do not show the line of best fit until you have found a best fit by yourself.

Find a minimum perpendicular fitting!

Vertical fitting

The segments are vertical. Move the line and try to find an optimal fitting. Do not show the line of best fit until you have found a best fit by yourself.

Find a minimum vertical fitting!

The green line is made with the Icon Best line fit tool. Which method is used by GeoGebra, a perpendicular or vertical fitting?

Regression in GeoGebra

 

Move the red points! Change the degree of the polynomial by changing the slider n!

Storks and babies, 2005

Country Storks · 1000 Babies/1000 population
Algeria 5.147 17
Austria 0.366 9
Belarus 11.5 11
Czech republic 0.811 9
Denmark 0.001 11
France 0.07 12
Germany 4.162 8
Hungary 5.5 10
Romania 4.4 11
Serbia and Montenegro 0.998 12
Slovakia 1.25 11
Switzerland 0.191 10
The Netherlands 0.326 11
Tunisia 0.405 16

Copy the numbers in the table above into GeoGebra. Selecting the entire table and then Copy/Paste to a GeoGebra spreadsheet should work.

Select the two columns of numbers and make a list of points.

Image

Choose "Dependent Objects"! If you create the points as free objects, they will no longer be attached to the values in the spreadsheet.

Image

Zoom out until you can see the points in the drawing pad. In order to see the regular tool bar, you must first click anywhere in the drawing pad.

Use the Icon Best Line Fit tool and click on the list, list1.

Changing the data

You can move any point in the drawing pad, the regression line is automatically updated and the value of the point is automatically updated in the spreadsheet. You can also change the value of a point in the spreadsheet.

Other fittings

You can fit the data points to other curves by using one of the commands FitExp[list1], FitLog[list1], FitLogistic[list1], FitPow[list1] or FitSin[list1]. Try them all, not all will be defined. Move the points around!.

Polynomial fitting

A (n-1)-degree polynomial will fit n data points exactly, i.e. each of the points will lie on the curve. High order polynomials can, however, be impractical for various reasons; they can be highly oscillatory and difficult to handle.

When making a polynomial fitting in GeoGebra you use two parameters; the first one is the list and the second is the degree of the polynomial. Try the command FitPoly[list1,n].

references:

Stork numbers from The sixth International White Stork Census: 2004-2005

Birth numbers from NationMaster.com

by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License

www.malinc.se