What is the Linear Regression Visual Tool?
Quick Answer: An interactive scatter plot that fits a least-squares regression line (y = mx + b) to points you place by clicking. Drag points to see how the slope, intercept, correlation coefficient (r), and R-squared change instantly. Residuals are shown as dashed lines.
Theory of Linear Regression
Simple linear regression finds the line that minimizes the sum of squared vertical distances (residuals) between observed y values and predicted y values. Given n points (xi, yi), the slope m = Σ(xi - x¯)(yi - y¯) / Σ(xi - x¯)2, and intercept b = y¯ - m x¯. The Pearson correlation coefficient r measures linear association strength (-1 to 1). R-squared = r2 is the proportion of variance in y explained by x. This tool demonstrates how adding or moving points changes the fit.
Step-by-Step Examples
Example 1: Perfect Positive Correlation
- Click a few points that lie almost on a straight rising line. The r value should approach 1.
- Observe the line passing through the centroid (mean x, mean y).
Example 2: Outlier Effect
- Create a tight cluster of points with positive trend, then add a single point far away in the opposite direction.
- Watch how the regression line tilts and r decreases. This shows the high leverage of outliers.
Example 3: No Correlation
- Add points randomly scattered across the canvas. The line will be nearly horizontal and r close to 0.
Frequently Asked Questions
How do I add data points?
Simply click anywhere on the canvas grid. A new point appears, and the regression statistics update immediately.
Can I move existing points?
Yes, click and drag any point to a new location. The line and residuals recalculate live as you drag.
What do r and R-squared mean?
r is the correlation coefficient (-1 to 1). R-squared = r² is the proportion of y-variance explained by x; e.g., 0.8 means 80% explained.
What are the dashed vertical lines?
They are residuals: the vertical distance from each point to the regression line. Toggle them off with the checkbox if desired.
Is this only for y vs x regression?
Yes, it models y as a linear function of x. For multiple regression or other curves, more advanced tools are needed.