Linear Regression Calculator
Simple linear regression is the modeling technique that predicts a dependent (response) variable from a single independent (predictor) variable. The analysis finds the line that best represents the relationship between X and Y by the method of least squares and produces an equation of the form ŷ = b₀ + b₁·x. Questions such as "how well does study time predict an exam score?" or "how much does demand change when the price goes up by one unit?" are typical applications.
This calculator returns the regression coefficients, the correlation, R² and adjusted R², the standard error of the estimate, and the significance test for the slope (t and p); it draws the observed values and the regression line on the same chart. Enter a value in the optional prediction field and you also get the expected y for that x straight from the equation.
Formula
b₁ = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)² b₀ = ȳ − b₁·x̄ ŷ = b₀ + b₁·x t = b₁ / SE(b₁) , df = n − 2
The coefficients come from the method of least squares: the chosen line is the one that minimizes the sum of squared residuals (observed − predicted). In simple regression R² equals the square of the Pearson correlation, and the t test of the slope returns the same p-value as the significance test of the correlation.
How to Calculate
- Paste the X (independent) and Y (dependent) values into the two fields in the same order; each row must belong to the same observation.
- If you wish, enter an x value in the prediction field — the expected y is computed automatically from the equation.
- Read the equation, R² and adjusted R², and the t and p values for the slope in the results section.
- Compare the observed Y values with the regression line on the chart; if the relationship does not look linear, do not use a linear model.
- Report the slope, R², and the significance together, and keep your predictions within the range of x covered by your data.
Worked Examples
Study hours and quiz score (small sample)
For five students the equation is ŷ = 2.20 + 0.60·x: one extra hour of study raises the score by 0.60 on average, and with R² = 0.600 the model explains 60% of the variance. With n = 5, however, the sample is far too small for the slope to reach significance (t(3) = 2.12; p = 0.124). The prediction for x = 4 is ŷ = 4.60.
Regression equation: ŷ = 2.20 + 0.60·x · Slope (b₁): 0.6000 · Intercept (b₀): 2.2000
Weekly study hours and exam score (12 students)
For a data set of 12 students the equation is ŷ = 50.03 + 2.10·x: each additional hour of study raises the score by 2.10 points on average. R² = 0.406 (40.6%) and the slope is significant (t(10) = 2.61; p = 0.026). A student who studies 7 hours a week has an expected score of ŷ = 64.71.
Regression equation: ŷ = 50.03 + 2.10·x · Slope (b₁): 2.0963 · Intercept (b₀): 50.0327
Price and demand (negative slope)
Between price (X) and units sold (Y) the equation is ŷ = 123.92 − 2.83·x: a one-unit rise in price is associated with an average drop of 2.83 units in demand. The model fits almost perfectly (R² = 0.996; p < 0.001), and the correlation is r = -0.998.
Regression equation: ŷ = 123.92 − 2.83·x · Slope (b₁): -2.8333 · Intercept (b₀): 123.9167