Simple Linear Regression
This Simple Linear Regression Calculator helps you analyze the relationship between two variables. It provides comprehensive analysis including model summary statistics, coefficient estimates, confidence intervals, and diagnostic tests. The calculator also generates a regression plot with the fitted line and confidence bands. To learn about the data format required and test this calculator, click here to populate the sample data.
Calculator
1. Load Your Data
2. Select Columns & Options
Learn More
Simple Linear Regression
Definition
Simple Linear Regression models the relationship between a predictor variable (X) and a response variable (Y) using a linear equation. It finds the line that minimizes the sum of squared residuals.
Key Formulas
Regression Line:
Slope:
Intercept:
R-squared:
Key Assumptions
Practical Example
Step 1: Data
1 | 2.1 | -2 | -3.82 | 4 | 7.64 |
2 | 3.8 | -1 | -2.12 | 1 | 2.12 |
3 | 6.2 | 0 | 0.28 | 0 | 0 |
4 | 7.8 | 1 | 1.88 | 1 | 1.88 |
5 | 9.3 | 2 | 3.38 | 4 | 6.76 |
Means: ,
Step 2: Calculate Slope ()
Step 3: Calculate Intercept ()
Step 4: Regression Equation
Step 5: Calculate
(98.6% of variation in Y explained by X)
Code Examples
library(tidyverse)
# Example data
data <- tibble(x = c(1, 2, 3, 4, 5),
y = c(2.1, 3.8, 6.2, 7.8, 9.3))
# Fit linear model
model <- lm(y ~ x, data=data)
# Print summary
summary(model)
# Get confidence intervals
confint(model)
# plot with ggplot2
ggplot(data, aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
theme_minimal()
import numpy as np
import pandas as pd
import statsmodels.api as sm
# Example data
X = [1, 2, 3, 4, 5] # predictor variable
y = [2.1, 3.8, 6.2, 7.8, 9.3] # response variable
# Add constant to X for intercept
X = sm.add_constant(X)
# Fit model
model = sm.OLS(y, X).fit()
# Print summary
print(model.summary())
# Get coefficients
print(f'Intercept: {model.params[0]:.4f}')
print(f'Slope: {model.params[1]:.4f}')
print(f'R-squared: {model.rsquared:.4f}')
Verification
Related Calculators
Help us improve
Found an error or have a suggestion? Let us know!