![Regression Line Optimization: Minimizing Orthogonal Perpendicular Distances (TLS) | Note: The Formula is Based on OLS Method.](https://static.wixstatic.com/media/4dd2e1_ebbf3d23b6d54fd78fdc7b3313a5de7e~mv2.png/v1/fill/w_980,h_839,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/4dd2e1_ebbf3d23b6d54fd78fdc7b3313a5de7e~mv2.png)
![Optimizing the Regression Line Using OLS: Minimizing Vertical Distances](https://static.wixstatic.com/media/4dd2e1_dfd051d2cdd745c3ae350bc8d4ab97ae~mv2.png/v1/fill/w_980,h_762,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/4dd2e1_dfd051d2cdd745c3ae350bc8d4ab97ae~mv2.png)
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.](https://static.wixstatic.com/media/4dd2e1_9309c3b54134427c94a9a06982705f7a~mv2.png/v1/fill/w_980,h_581,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/4dd2e1_9309c3b54134427c94a9a06982705f7a~mv2.png)
Python Enabled Activity
![Python Output - Regression Line Graphing](https://static.wixstatic.com/media/4dd2e1_e6ed163a9376421799945f9fb84c3a75~mv2.png/v1/fill/w_640,h_480,al_c,q_85,enc_avif,quality_auto/4dd2e1_e6ed163a9376421799945f9fb84c3a75~mv2.png)
Instructions: Open the Python script with Notepad and study the code.
What Python functionalities have you learned?
Coding Concepts and Syntaxes to Explore:
DataFrames
polyfit Parameters (Inputs and Outputs)
Parameters of the scatter Command (plt.scatter)
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.
Comments