The Least-Squares Regression simulation from PhET lets you create your own scatter plot or use real-world data, and then fit a line to it. You can see how each data point changes the correlation coefficient and the best-fit line, and compare your own line with the best-fit line. It is free, runs in any browser on a phone, tablet or laptop, and it is a great fit for the correlation and regression lessons in Tamil Nadu State Board (Samacheer Kalvi) Maths and Statistics.
What is the Least-Squares Regression simulation?
This interactive simulation lets you place points on a scatter plot and fit a straight line through them. You can drag the points, add new ones or remove them, and watch how the best-fit line, the correlation coefficient r and the squared residuals respond. Because it runs on HTML5, there is nothing to install, and it works on phones, tablets, Chromebooks and computers.
High school and university
Correlation, residuals and linear regression
Phone, tablet, Chromebook, PC
English
PhET’s learning goals are to interpret r as points are added, moved or removed, to interpret the sum of the squared residuals while fitting a line by hand and for the best-fit line, to compare the two, and to decide whether a linear fit is appropriate.
Launch the Least-Squares Regression simulation online
Tap or click inside the player and start exploring. Use the full-screen button in the player for a bigger view.
Credit: University of Colorado Boulder
How to use the Least-Squares Regression simulation, step by step
- Predict first. Before you add a point, say whether r will go up or down.
- Make a scatter plot. Create your own data points, or use the real-world data.
- Fit a line by hand. Place a line as close to the points as you can and note the sum of the squared residuals.
- Show the best-fit line. Compare its sum of squared residuals with your own line.
- Move the points. Add, drag or remove points, including an outlier, and watch r and the best-fit line change.
Tip for students: always look at the scatter plot first. A straight line is only a good model when the points follow a straight-line pattern.
The idea behind the simulation: least squares
y = m x + b, with the smallest Σ(residual)²
A residual is the vertical gap between a data point and the line: residual = actual y − predicted y. The least-squares line is the one that makes the sum of the squared residuals as small as possible. Its slope is m = Sxy ÷ Sxx and its intercept is b = ȳ − m × x̄, where Sxy = Σ(x − x̄)(y − ȳ) and Sxx = Σ(x − x̄)². The correlation coefficient is r = Sxy ÷ √(Sxx × Syy). It runs from −1 to +1.
Worked example: Take x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 6. The means are 3 and 4.2. Sxx = 10, Sxy = 8 and Syy = 8.8. The slope is 8 ÷ 10 = 0.8 and the intercept is 4.2 − 0.8 × 3 = 1.8, so the best-fit line is y = 0.8x + 1.8. The correlation is r = 8 ÷ √(10 × 8.8) ≈ 0.853, and the sum of squared residuals is 2.4.
Regression key terms explained
These are the words you will meet while using the Least-Squares Regression simulation, with simple meanings.
Scatter plot
A graph of data points, one for each pair of values (x, y).
Correlation coefficient (r)
A number from −1 to +1 that shows how closely the points follow a straight line.
Best-fit line
The line that fits the points best. The least-squares line is the best-fit line.
Residual
The gap between a point and the line, measured up or down.
Sum of squared residuals
The total of all the squared residuals. The best-fit line makes it as small as possible.
Outlier
A point far away from the pattern of the others.
Slope
How much y changes when x goes up by 1.
Linear regression
Fitting a straight line to data to describe the trend and make predictions.
Common mistakes: Thinking that a high r always means a straight-line pattern, forgetting that one outlier can change the line a lot, and mixing up correlation with cause and effect.
Try the regression calculator (practice what you explore)
Type your data as lists separated by commas. The calculator finds the best-fit line, r and the sum of squared residuals. Then try your own line and compare. Tap a “what if” button to add an outlier.
What happens when you change a variable
| Change | Effect |
|---|---|
| Points close to a rising line | r is close to +1 |
| Points close to a falling line | r is close to −1 |
| Points scattered with no pattern | r is close to 0 |
| Add an outlier | r and the best-fit line can change a lot |
| Move your line away from the best-fit line | The sum of squared residuals goes up |
Classroom activities for teachers
The Least-Squares Regression simulation fits a single 40-minute period.
- Predict and test (10 min): students predict how r changes when a point is moved, then check.
- Beat the best line (10 min): students fit a line by hand and try to get as close as they can to the least squares total.
- Outlier hunt (10 min): students add an outlier and describe how the line and r change.
- Exit ticket (10 min): students explain in two sentences why a small sum of squared residuals means a better line.
Looking for the matching chapters? Browse the Maths and Statistics books on TN SchoolBooks and download the Samacheer Kalvi PDFs, then use this simulation to make the correlation and regression lessons visual. More free simulations and textbook PDFs are on the home page.
Quick quiz: test your understanding of regression
Score: 0 / 5
Least-Squares Regression simulation: frequently asked questions
Is the Least-Squares Regression simulation free?
Yes. PhET simulations are free to run online in a browser. Check PhET’s licensing page for reuse terms.
Does it work on a mobile phone?
Yes. It is built with HTML5 and works on phones, tablets and Chromebooks. Use landscape mode or the player’s full-screen button for a bigger view.
What does the least-squares line minimize?
It minimizes the sum of the squared residuals, where a residual is the vertical gap between a data point and the line.
What does the correlation coefficient r tell you?
The correlation coefficient r tells you how closely the points follow a straight line. Values near +1 or −1 mean a strong linear pattern, and values near 0 mean little or no linear pattern.
The Least-Squares Regression simulation turns a table of numbers into a picture you can drag, fit and test. Explore it, take the quiz above, and keep experimenting until judging a line of best fit feels easy.