Linear Regression Calculator
Fit a line to predict Y from X.
Predictor variable
Response variable
Optional: Get predicted Y with confidence interval
Load example data:
Enter paired X and Y values for linear regression
Minimum 3 data points required
What Is Simple Linear Regression?
Simple linear regression models the relationship between two variables by fitting a straight line to the data. It allows you to predict Y (the outcome) from X (the predictor).
Question answered: "What's the best-fitting line, and how well does X predict Y?"
Examples:
- "How do sales change with advertising spending?"
- "Predict exam score from study hours."
- "What's the relationship between temperature and ice cream sales?"
The Regression Equation
Or in alternative notation:
Where:
- (or ) = Y-intercept (value of Y when X = 0)
- (or ) = slope (change in Y for one-unit increase in X)
- = predicted Y value
Calculating the Coefficients
Slope:
Or:
Intercept:
The line always passes through the point .
Example Calculation
Data: Advertising spend (X, $1000s) and sales (Y, units)
| X | Y |
|---|---|
| 2 | 180 |
| 4 | 220 |
| 6 | 290 |
| 8 | 350 |
| 10 | 400 |
Summary statistics:
- xΜ = 6, Θ³ = 288
- Sxx = 40, Sxy = 1100
Slope: b = 1100 / 40 = 27.5
Intercept: a = 288 - 27.5 Γ 6 = 123
Equation: ΕΆ = 123 + 27.5X
Interpretation: Each $1,000 increase in advertising is associated with 27.5 additional unit sales.
Interpreting the Slope
b = 27.5 means:
- For every 1-unit increase in X, Y increases by 27.5 on average
- The relationship is positive (Y increases as X increases)
- This is an average effectβindividual observations vary
Units matter: If X is in thousands of dollars and Y is in units sold, then: "$1,000 more advertising β 27.5 more units sold"
Interpreting the Intercept
a = 123 means:
- When X = 0, the predicted Y is 123
- Zero advertising predicts 123 unit sales
Caution: Interpret literally only if X = 0 is meaningful and within your data range.
If your data spans X = 2 to 10, the intercept is extrapolation and may not be meaningful.
Residuals and Fit
Residual = Observed - Predicted
| X | Y | ΕΆ | Residual |
|---|---|---|---|
| 2 | 180 | 178 | +2 |
| 4 | 220 | 233 | -13 |
| 6 | 290 | 288 | +2 |
| 8 | 350 | 343 | +7 |
| 10 | 400 | 398 | +2 |
Residuals should be small and randomly scattered.
R-Squared (Coefficient of Determination)
Or: (squared correlation)
For our example: r = 0.995, so RΒ² = 0.99
Interpretation: 99% of variation in sales is explained by advertising spend.
Standard Error of the Estimate
Measures typical prediction error.
For our example: SE β 7.9 units
Predictions are typically off by about 8 units.
Testing the Slope
Is the slope significantly different from zero?
Hβ: Ξ²β = 0 (no relationship) Hβ: Ξ²β β 0 (relationship exists)
Test statistic:
Where
If p < Ξ±, the slope is statistically significant.
Confidence Interval for Slope
Gives range of plausible population slopes.
Prediction
Point Prediction
For X = 7: ΕΆ = 123 + 27.5(7) = 315.5 units
Prediction Interval
Accounts for uncertainty in both the line and individual variation:
Prediction intervals are always wider than confidence intervals.
Assumptions (LINE)
Linearity
The relationship between X and Y is linear.
Check: Scatterplot, residual plot
Independence
Observations are independent.
Violation: Time series data, clustered data
Normality
Residuals are normally distributed.
Check: Histogram of residuals, QQ plot
Equal Variance (Homoscedasticity)
Residual spread is constant across X values.
Check: Residual plot (should show random scatter)
Residual Diagnostics
Good residual plot:
- Random scatter around zero
- No patterns or trends
- Constant spread
Problems to detect:
- Curvature β non-linear relationship
- Funnel shape β heteroscedasticity
- Clusters β potential subgroups
Common Issues
Extrapolation
Predicting outside the range of observed X values.
If data spans X = 2 to 10, predicting at X = 20 is risky.
Outliers
Unusual points can heavily influence the line.
High leverage: Extreme X values High influence: Points that change the line substantially
Confounding
Third variables may explain the relationship.
Regression doesn't prove causation.
Applications
Business
Sales forecasting, demand modeling, pricing analysis.
Science
Calibration curves, dose-response relationships.
Economics
Consumption functions, price elasticity.
Medicine
Growth charts, treatment response modeling.
Engineering
Quality control, process optimization.
Regression vs. Correlation
| Aspect | Correlation | Regression |
|---|---|---|
| Purpose | Measure relationship | Predict/explain |
| Direction | Symmetric | X predicts Y |
| Output | r (single number) | Equation (a, b) |
| Interpretation | Strength | Rate of change |
Connection: rΒ² = RΒ² in simple regression
Reporting Results
Standard format:
"Simple linear regression revealed that advertising spending significantly predicted sales, b = 27.5, SE = 1.38, t(3) = 19.9, p < .001. The model explained 99% of the variance in sales (RΒ² = .99)."
With equation:
"The regression equation was: Sales = 123 + 27.5 Γ Advertising, F(1, 3) = 397, p < .001, RΒ² = .99."
Historical Context
Francis Galton pioneered regression in the 1880s studying heredityβspecifically, why children of tall parents "regressed" toward average height.
Karl Pearson formalized the mathematics, connecting regression to correlation.
The term "regression" persists even though modern applications rarely involve "regression toward the mean" in Galton's sense.
Related Calculations
- Multiple Regression β Multiple predictors
- Pearson Correlation β Relationship strength
- R-Squared Calculator β Model fit
- Residual Analysis β Assumption checking
- Prediction Interval Calculator β Uncertainty in predictions
Summary
Simple linear regression fits the line Y = a + bX to model how X predicts Y. The slope (b) represents the change in Y per unit change in X; the intercept (a) is the predicted Y when X = 0. RΒ² indicates the proportion of variance explained. Test the slope for significance and check assumptions using residual plots. Report the equation, RΒ², and significance test. Remember that regression shows association, not causation, and avoid extrapolating beyond your data range.