How to Use the Linear Regression Calculator
This calculator allows you to perform simple linear regression using the ordinary least squares method. You can enter paired X and Y values manually or upload a dataset containing the variables you want to analyze.
To use the calculator, choose one of the following data input options:
Option 1: Raw Data
- Select Raw Data.
- Enter the predictor variable values in the X input field and the response variable values in the Y input field. Make sure the observations are paired in the same order. You can also copy and paste two columns directly from Excel or Google Sheets.
- Edit the variable names if necessary.
- Select the number of decimal places you want to display.
- Click Calculate.
Option 2: Upload Dataset
- Select Upload Dataset and upload a CSV, TSV, TXT, XLS, or XLSX file.
- Preview the uploaded data to confirm that the observations have been imported correctly. If the file contains multiple worksheets, select the worksheet you want to analyze.
- Check the First row contains column names option if the first row contains variable names.
- Select the predictor variable (X) and response variable (Y) from the available columns.
- Click Analyze Selected Variables.
The calculator will return the least squares regression equation, regression graph, Model Summary, ANOVA table, regression coefficients, p-values, and 95% confidence intervals. It also allows you to predict Y for a given value of X.
Tip: This calculator supports up to 5,000 observations. Rows containing missing values in either of the selected variables are automatically excluded from the analysis.
If you only want to calculate the slope and intercept manually, use the Line of Best Fit Calculator to get a clear step-by-step solution explaining how the regression equation is obtained. However, if you only need to visualize the relationship between the response variable and the predictor, you may use the scatter plot maker.
What Is Simple Linear Regression?
Simple linear regression is a statistical method used to model the linear relationship between one numerical predictor variable and one numerical response variable.
For example, a researcher may want to determine whether the number of hours an employee spends in training can be used to predict their performance score.
In this case:
- Training Hours is the predictor variable, X.
- Performance Score is the response variable, Y.
Simple linear regression estimates a straight-line relationship between these variables and allows us to determine whether Training Hours significantly predicts Performance Score.
The method is called simple linear regression because the model contains only one predictor variable.
If you want to perform a linear regression using two or more predictors, use the Multiple Linear Regression Calculator instead.
Simple Linear Regression Equation
The estimated simple linear regression equation is:
Where:
- ŷ is the predicted value of Y.
- b₀ is the intercept.
- b₁ is the regression coefficient or slope.
- x is the value of the predictor variable.
For example, suppose the regression equation is: ŷ = 28.5 + 2.7x. In this case, the slope is b₁ = 2.7. This means that every one-unit increase in X is associated with an estimated increase of 2.7 units in Y. The intercept is b₀ = 28.5, which indicates that the predicted value of Y when X = 0 is 28.5.
Note: The interpretation of the intercept depends on whether X = 0 is meaningful and within a reasonable range for the data being analyzed.
How Is the Least Squares Regression Line Calculated?
The least squares method is used to find the regression line that best fits a set of paired X and Y observations. It works by minimizing the sum of squared differences between the observed Y values and the values predicted by the regression equation.
These differences are called residuals.
For example, suppose the observed value of Y is 15, while the predicted value is 13.
Residual = Observed Y − Predicted Y
= 15 − 13
= 2
The least squares method squares each residual and finds the regression line that minimizes their sum.
This is why simple linear regression is also commonly referred to as ordinary least squares (OLS) regression when the coefficients are estimated using this method.
Least Squares Regression Formula
The slope of the least squares regression line is calculated using the formula:
Where:
- n is the number of paired observations.
- Σxy is the sum of the products of X and Y.
- Σx is the sum of the X values.
- Σy is the sum of the Y values.
- Σx² is the sum of the squared X values.
After calculating the slope, we find the intercept using the formula:
b₀ = ȳ − b₁x̄
Where x̄ and ȳ are the means of X and Y, respectively.
We then substitute the slope and intercept into the regression equation:
ŷ = b₀ + b₁x
This gives the least squares regression line.
The Linear Regression Calculator uses this method to estimate the slope and intercept. It also calculates the model fit statistics, coefficient tests, ANOVA, and confidence intervals.
For a complete example showing how to calculate the slope and intercept by hand, see the Line of Best Fit Calculator.
Understanding the Linear Regression Graph
After calculating the regression model, the calculator displays a scatter plot with the fitted least squares regression line.
In the graph:
- The horizontal axis represents the predictor variable (X).
- The vertical axis represents the response variable (Y).
- Each point represents one paired observation.
- The green line represents the fitted regression equation.
The graph allows you to see how closely the observations follow a straight-line pattern.
For example, if most observations are close to the fitted line, the regression model generally provides a better fit than when the observations are widely scattered around it.
The graph can also help you identify unusual observations or a curved relationship that may not be adequately represented by a straight line.
However, the graph alone cannot determine whether the regression model is statistically significant. You should also examine the Model Summary, ANOVA, and Coefficients tables.
Understanding the Simple Linear Regression Outputs
After you click Calculate, the calculator displays the regression equation and the main results. It then organizes the detailed statistical output into three tables:
- Model Summary
- ANOVA
- Coefficients
Each table provides different information about the regression model. The sections below explain the statistics reported in each table and how to interpret them.
1) Model Summary
The Model Summary provides an overview of how well the regression model fits the data. It reports:
- R: Measures the relationship between the observed Y values and the values predicted by the regression model. In simple linear regression, R is reported as the positive square root of R². Therefore, use the sign of the slope or standardized coefficient (β) to determine whether the relationship between X and Y is positive or negative.
- R²: Shows the proportion of variation in Y accounted for by the regression model. For example, R² = 0.64 means that the model explains approximately 64% of the variation in Y.
- Adjusted R²: Adjusts R² for the sample size and number of predictors. In simple linear regression, adjusted R² is usually close to R².
- SE: Gives the standard error of the estimate. It measures the typical size of the residuals, or the differences between the observed and predicted Y values. Smaller values indicate that the observations tend to fall closer to the fitted regression line.
- N: Shows the number of complete observations included in the analysis.
You can learn more about R² and how to calculate it using the Coefficient of Determination Calculator.
2) ANOVA
The ANOVA table tests whether the regression model significantly predicts Y. It separates the total variation in Y into the variation explained by the model and the variation that remains unexplained.
The table reports:
- Regression SS: The amount of variation in Y accounted for by X.
- Residual SS: The amount of variation in Y that the regression model does not explain.
- Total SS: The total variation in Y. It equals Regression SS + Residual SS.
- df: The degrees of freedom associated with each source of variation.
- MS: The mean square, calculated by dividing each sum of squares by its corresponding degrees of freedom.
- F: The F statistic used to test the overall regression model.
- p: The p-value associated with the F statistic.
For simple linear regression, the hypotheses for the overall model are:
- H₀: β₁ = 0 (X does not linearly predict Y in the population).
- H₁: β₁ ≠ 0 (X linearly predicts Y in the population).
If p < .05, we reject the null hypothesis at the 5% significance level and conclude that the regression model is statistically significant.
For example, F(1, 18) = 12.46, p = .002 indicates that the regression model is statistically significant.
3) Coefficients
The Coefficients table shows the estimated intercept and the regression coefficient for X. It allows you to determine the direction, size, and statistical significance of the relationship between X and Y.
The table reports:
- B: The unstandardized regression coefficient. For X, B represents the expected change in Y for a one-unit increase in X. The intercept B gives the predicted value of Y when X = 0.
- SE: The standard error of B. It indicates the uncertainty associated with the estimated coefficient.
- β: The standardized regression coefficient. It expresses the relationship in standard deviation units. In simple linear regression, β equals Pearson’s correlation coefficient, r.
- t: The t statistic used to test whether the regression coefficient differs significantly from zero.
- p: The p-value for the coefficient test. If p < .05, the predictor is statistically significant at the 5% significance level.
- 95% CI for B: Gives the 95% confidence interval for the unstandardized coefficient. If the interval for the predictor does not contain zero, the coefficient is statistically significant at α = .05 under the usual two-sided test.
For example, suppose Training Hours has B = 2.81, SE = 0.29, t = 9.79, p < .001.
This means that each additional hour of training is associated with an estimated increase of 2.81 units in Y. Since p < .001, Training Hours is also a statistically significant predictor of Y.
Tip: The regression equation uses the unstandardized B coefficients, not the standardized β coefficients.
Example: Linear Regression
A company wants to determine whether weekly advertising expenditure can be used to predict weekly sales.
The following data were collected for eight weeks.
| Advertising Expenditure (X) | Weekly Sales (Y) |
|---|---|
| 5 | 42 |
| 7 | 46 |
| 8 | 54 |
| 10 | 53 |
| 12 | 65 |
| 13 | 61 |
| 15 | 74 |
| 18 | 77 |
Perform a simple linear regression to determine whether advertising expenditure significantly predicts weekly sales.
Solution
To perform the analysis using the calculator:
- Select Raw Data.
- Enter the Advertising Expenditure values in the X input field.
- Enter the Weekly Sales values in the Y input field.
- Rename X to Advertising Expenditure and Y to Weekly Sales.
- Click Calculate.
The calculator gives the least squares regression equation as:
Predicted Weekly Sales = 28.0833 + 2.8106(Advertising Expenditure)
It also displays the regression graph and the following statistical tables.
Model Summary Table
| Model | R | R² | Adjusted R² | SE | N |
|---|---|---|---|---|---|
| 1 | 0.9701 | 0.9411 | 0.9313 | 3.2981 | 8 |
From the table, the model gives R² = 0.9411. Therefore, approximately 94.11% of the variation in Weekly Sales is accounted for by its linear relationship with Advertising Expenditure.
After adjusting for the sample size, Adjusted R² = 0.9313. The standard error of the estimate is 3.2981.
ANOVA Table
| Source | SS | df | MS | F | p |
|---|---|---|---|---|---|
| Regression | 1042.7348 | 1 | 1042.7348 | 95.8614 | < .001 |
| Residual | 65.2652 | 6 | 10.8775 | — | — |
| Total | 1108.0000 | 7 | — | — | — |
The ANOVA table shows that the regression model is statistically significant, F(1, 6) = 95.8614, p < .001. Therefore, there is sufficient evidence that Advertising Expenditure significantly predicts Weekly Sales.
Coefficients Table
| Term | B | SE | β | t | p | 95% CI for B |
|---|---|---|---|---|---|---|
| Intercept | 28.0833 | 3.3661 | — | 8.3429 | < .001 | [19.8467, 36.3199] |
| Advertising Expenditure | 2.8106 | 0.2871 | 0.9701 | 9.7909 | < .001 | [2.1082, 3.5130] |
The regression coefficient for Advertising Expenditure is B = 2.8106. Therefore, for every one-unit increase in Advertising Expenditure, Weekly Sales are predicted to increase by approximately 2.81 units.
Advertising Expenditure is also a statistically significant predictor of Weekly Sales, t(6) = 9.7909, p < .001.
Moreover, the 95% confidence interval for the coefficient is [2.1082, 3.5130]. Since this interval does not contain zero, it supports the conclusion that Advertising Expenditure has a significant positive relationship with Weekly Sales.
How to Report Linear Regression Results in APA Style
When reporting a linear regression in APA style, include the overall model test, R², and the regression coefficient for the predictor. You can also report the standard error, standardized coefficient, and 95% confidence interval where appropriate.
Using the example above, you could report the results as follows:
A simple linear regression was conducted to determine whether Advertising Expenditure predicted Weekly Sales. The regression model was statistically significant, F(1, 6) = 95.86, p < .001, R² = .941. Advertising Expenditure was a significant positive predictor of Weekly Sales, B = 2.81, SE = 0.29, β = .970, t(6) = 9.79, p < .001, 95% CI [2.11, 3.51].
Making a Prediction From the Regression Model
Once the regression equation has been calculated, you can use it to predict Y for a given value of X.
Using the previous example, the regression equation is:
Predicted Weekly Sales = 28.0833 + 2.8106(Advertising Expenditure)
Suppose we want to predict weekly sales when advertising expenditure is 11 units.
Since X = 11, we substitute this value into the regression equation.
Predicted Weekly Sales = 28.0833 + 2.8106(11)
= 59.0000
Therefore, the predicted Weekly Sales are 59 units when Advertising Expenditure is 11 units.
You can make this calculation directly using the Predict Y option in the calculator.
Confidence Interval vs. Prediction Interval
Besides the predicted value, the calculator also provides a 95% confidence interval and a 95% prediction interval.
- 95% Confidence Interval: Gives an interval estimate for the mean value of Y at a specified value of X.
- 95% Prediction Interval: Gives an interval for the value of a single new observation at a specified value of X.
For example, using the previous data and X = 11, the calculator gives:
- Predicted Weekly Sales = 59.0000
- 95% confidence interval for the mean response = [56.1468, 61.8532]
- 95% prediction interval for a new observation = [50.4403, 67.5597]
The prediction interval is wider because it accounts for both uncertainty in the estimated regression line and variation among individual observations.
Note: Predictions are generally more reliable when the X value is within the range of the data used to fit the model. Predicting far outside this range is called extrapolation and should be interpreted cautiously.
Simple Linear Regression vs. Line of Best Fit
A least squares regression line is also called a line of best fit when referring to the straight line fitted using the least squares method.
Both calculators use the same underlying approach to find the slope and intercept. However, the two tools on StatCalc.net serve different purposes.
| Line of Best Fit Calculator | Linear Regression Calculator |
|---|---|
| Focuses on finding the fitted line | Focuses on statistical regression analysis |
| Shows how to calculate the slope and intercept | Reports regression coefficient tests |
| Provides a step-by-step manual solution | Reports Model Summary and ANOVA |
| Displays the regression graph | Displays the regression graph |
| Returns the correlation coefficient and R² | Returns R², adjusted R², and standard errors |
| Useful for learning least squares calculations | Useful for analyzing research data and making predictions |
Use the Line of Best Fit Calculator if you want to learn how the least squares regression equation is calculated manually.
However, if you want to test whether a predictor is statistically significant, interpret regression coefficients, or calculate confidence and prediction intervals, use the Linear Regression Calculator.
Simple vs. Multiple Linear Regression
The main difference between simple and multiple linear regression is the number of predictor variables included in the model.
| Simple Linear Regression | Multiple Linear Regression |
|---|---|
| One response variable | One response variable |
| One predictor variable | Two or more predictor variables |
| ŷ = b₀ + b₁x | ŷ = b₀ + b₁x₁ + b₂x₂ + … |
| Estimates one slope coefficient | Estimates several slope coefficients |
| Does not have multicollinearity between predictors | Multicollinearity may need to be assessed |
For example, simple linear regression can be used to predict Weekly Sales using Advertising Expenditure alone.
However, if you also want to include Product Price and Marketing Budget as predictors, you would use multiple linear regression.
You can perform this analysis using the Multiple Linear Regression Calculator.
Assumptions of Simple Linear Regression
Before interpreting the p-values and confidence intervals, check whether the main assumptions of simple linear regression are reasonably satisfied.
- Linearity: The relationship between X and the expected value of Y should be approximately linear. A scatter plot is useful for identifying strong curves or other nonlinear patterns.
- Independence: The observations should be independent of one another. For example, one participant’s value should not improperly determine another participant’s value.
- Homoscedasticity: The spread of the residuals should remain reasonably constant across the fitted values. A strong funnel-shaped residual pattern may indicate unequal variance.
- Normality of Residuals: The residuals should be approximately normally distributed when using the usual t and F tests, particularly in small samples. The X and Y variables themselves do not have to be normally distributed.
- No Highly Influential Outliers: Unusual observations can have a large effect on the slope, intercept, and statistical tests. Therefore, you should examine the data and consider whether any observations are unusually influential.
The regression graph can help you examine the overall relationship between X and Y. However, a residual plot and other diagnostic checks may be needed to evaluate some of these assumptions more closely.
Linear Regression vs. Correlation
Linear regression and correlation both examine linear relationships between numerical variables, but they answer different questions.
| Linear Regression | Correlation |
|---|---|
| Predicts Y from X | Measures association between X and Y |
| Distinguishes between predictor and response | Treats the two variables symmetrically |
| Produces a regression equation | Produces Pearson’s r |
| Estimates slope and intercept | Does not estimate a prediction equation |
| Can test whether X significantly predicts Y | Tests whether the linear association differs from zero |
For example, correlation can tell us whether Advertising Expenditure and Weekly Sales have a positive or negative linear relationship and how strong the relationship is.
Linear regression goes a step further by estimating an equation that can be used to predict Weekly Sales from Advertising Expenditure.
If you only want to measure the strength and direction of a linear relationship, use the Correlation Coefficient Calculator.
Can a linear regression calculator predict future values?
Yes. Once the regression equation has been calculated, you can enter a new X value to predict Y. This calculator also provides a 95% confidence interval for the mean response and a 95% prediction interval for an individual observation.
Does a significant linear regression prove causation?
No. A statistically significant regression indicates evidence of a linear relationship between X and Y. It does not, by itself, prove that changes in X cause changes in Y. Causal conclusions depend on the study design and other supporting evidence.
Frequently Asked Questions
A linear regression calculator is an online tool that fits a straight-line relationship between one numerical predictor variable and one numerical response variable. This calculator uses the least squares method and provides the regression equation, graph, R², ANOVA, coefficient tests, p-values, confidence intervals, and predictions.
A least squares regression calculator finds the regression line that minimizes the sum of squared differences between the observed and predicted values. This calculator uses ordinary least squares to estimate the slope and intercept of a simple linear regression model.
Not exactly. Simple linear regression refers to a linear model with one predictor variable, while ordinary least squares is a method used to estimate the regression coefficients. However, a simple linear regression model is commonly fitted using the least squares method.
Yes. You can upload CSV, TSV, TXT, XLS, or XLSX files. After uploading the dataset, preview the observations and select the variables you want to use as X and Y. The calculator supports up to 5,000 data rows.
B is the unstandardized regression coefficient and is expressed in the original units of X and Y. However, β is the standardized coefficient and expresses the relationship in standard deviation units. In simple linear regression, β equals Pearson’s correlation coefficient, r.
In simple linear regression with an intercept and one predictor, the overall F-test and the t-test for the slope test the same null hypothesis. Therefore, F = t², and both tests produce the same p-value.
