top of page
Search

GeoGebra Based Activity + Python Enabled Activity: Regression Line

Writer's picture: Annauen RavacioAnnauen Ravacio

Updated: Jan 7


Regression Line Optimization: Minimizing Orthogonal Perpendicular Distances (TLS) | Note: The Formula is Based on OLS Method.
Regression Line Optimization: Minimizing Orthogonal Perpendicular Distances (TLS) | Note: The Formula is Based on OLS Method.


Optimizing the Regression Line Using OLS: Minimizing Vertical Distances
Optimizing the Regression Line Using OLS: Minimizing Vertical Distances


This GeoGebra activity allows users to explore regression analysis by interacting with a set of data points and a regression line. Users can estimate the optimized slope and y-intercept of the best-fit line, comparing it to a manually derived regression line. The applet visualizes both non-optimized and optimized sums of squares, using the concepts of TLS and OLS. By observing how the regression line minimizes errors between the data points and the line, users can better understand these methods. Additionally, the activity guides users in using the Algebra pane to graph the regression line and leveraging the spreadsheet to replicate the process, providing hands-on experience with regression concepts and formula derivation.


Note:

OLS: Minimizes vertical distances; assumes no error in x; simpler to compute.

TLS (Orthogonal Regression): Minimizes shortest (perpendicular) distances;

accounts for errors in both variables; used in specialized scenarios.

Total Least Squares (TLS) is a beautiful application of Linear Algebra.



For the manual sketching of the regression line: After determining the slope and y-intercept (when x = 0), please also find the x-intercept (when y = 0) to guide the manual sketching of the regression line. Otherwise, assign a value of y that is in the middle of the range of y-values and compute the corresponding value of x to get another point using the derived regression line equation.
For the manual sketching of the regression line: After determining the slope and y-intercept (when x = 0), please also find the x-intercept (when y = 0) to guide the manual sketching of the regression line. Otherwise, assign a value of y that is in the middle of the range of y-values and compute the corresponding value of x to get another point using the derived regression line equation.

Python Enabled Activity



Python Output - Regression Line Graphing
Python Output - Regression Line Graphing






Instructions: Open the Python script with Notepad and study the code.

What Python functionalities have you learned?

Coding Concepts and Syntaxes to Explore:

  1. DataFrames

  2. polyfit Parameters (Inputs and Outputs)

  3. Parameters of the scatter Command (plt.scatter)

  4. Parameters of the plot Command (plt.plot)

Save the Python script, together with the Speed Test data source in Excel.


Please ensure that you are running within the Python virtual environment.

To create a Python virtual environment, use the following command:

python -m venv myenv

(This command will create the virtual environment. It is recommended to create it on your Desktop.)


Navigate to the virtual environment directory:

cd C:\Users\<Your Profile name>\Desktop\myenv


Activate the virtual environment:

Scripts\activate


Ensure the needed packages are installed:

pip install openpyxl pandas numpy matplotlib


Once the virtual environment is activated and the necessary packages are installed, you can run your Python script:

python "C:\Users\<Your Username>\Desktop\Speed Test.py"


Reference and Source of Inspiration:

Baccay, E. S., & Belecina, R. R. (July 2023). Statistics and Probability. Rex Marketing.


Thank you for your kind support.

41 views0 comments

Recent Posts

See All

The Essence of Hellenistic Period

Abstract This reflection explores the essence of the Hellenistic Period, focusing on the spread of Greek culture and its influence on...

Comments


bottom of page