What Is Simple Linear Regression and How Does It Work?

Simple linear regression summarizes how one thing tends to change as another changes by drawing a single straight line through a cloud of data points. That line lets you predict, such as estimating sales from past trends or a health outcome from one measurement.1GeeksforGeeks. Linear Regression in Machine learning2PubMed Central. Application and interpretation of linear-regression analysis The line is always a best guess rather than an exact rule, and the method will draw one even through data that aren’t straight at all, so knowing when to trust it matters as much as knowing how it works. The idea grew from Francis Galton’s work on how traits of sweet peas passed from parent plants to offspring.3Journal of Statistics Education. Galton, Pearson, and the Peas: A Brief History of Linear Regression for Statistics Instructors

The Equation Behind the Line

The method uses exactly one input, often called x or the independent variable, to predict one outcome, called y.4DISCOVERY: Foundations of AI and Data Science. Simple Linear Regression – Data Science Discovery Predicting exam scores from hours studied is a simple regression.

The fitted line is written y = b0 + b1·x, where b0 is the intercept and b1 is the slope.4DISCOVERY: Foundations of AI and Data Science. Simple Linear Regression – Data Science Discovery The slope is how much y changes for every one-unit increase in x.5VSNi. Pearson Correlation vs. Simple Linear Regression The intercept is the predicted y when x is zero, the point where the line crosses the vertical axis. If x = 0 never happens in your data, such as a weight of zero, the starting value is just a mathematical anchor, not a real prediction.

Take a line like price = 50,000 + 200 × square metres. Read aloud, the 200 says each extra square metre adds about 200 to the predicted price. Making a prediction is just plugging in x: a 100-square-metre home predicts 70,000.

The sign of the slope tells you the direction. A positive slope means y rises as x rises. A negative slope means y falls as x rises, like car value with age. A slope near zero means x barely moves y. The size of the slope depends on units, so changing metres to feet changes the number.

Real data never sit exactly on a line, so the model adds an error term for each point: y = α + βx + ε.6Wikipedia. Simple linear regression The true line for the whole population is unknown, and the b0 and b1 you calculate are estimates of it from your sample.7Statistics Fundamentals. What Is Simple Linear Regression and How Does It Work? A different sample would give a slightly different line.

A line is only grounded in the range of x values that were actually observed. Predicting far outside that range is a guess about a pattern nobody measured. A line fitted to studying times of 1 to 5 hours says nothing reliable about someone who studies 40 hours, since scores cannot rise forever and the relationship may bend or level off. Predicting inside the observed range is much safer. Before trusting a prediction, check that the x value you plug in falls within the range of x values in the original data.

How the Best-Fit Line Is Found

For each point, the residual is the vertical gap between the actual y and the line’s predicted y. The least-squares method chooses the line that makes the total of all squared residuals as small as possible.8Wikipedia. Least squares No other straight line has a smaller overall squared error on that data.9DataCamp. What Is Simple Linear Regression and How Does It Work?

Squaring stops positive and negative misses from cancelling each other out. It also makes big misses count far more than small ones, so a point 10 units off weighs 100 times as much as one 1 unit off. That means a few far-off points can pull the whole line toward them, a weakness taken up later.

Regression measures each miss straight up or down because the goal is to predict y from a known x, so the error that matters is the error in y. Measuring the shortest diagonal distance to the line would be a different method with a different answer.

You never do this arithmetic by hand. Spreadsheets and stats tools compute the slope and starting value instantly from a fixed formula, with no trial and error. Excel’s trendline or LINEST, and similar tools, all use least squares by default. Your job is choosing sensible data and checking the result.

Reading R-Squared and the P-Value

R-squared is the share of the variation in y that the straight line explains, from 0% to 100%.10Statistics By Jim. How To Interpret R-squared in Regression Analysis Near 100% means points hug the line, while near 0% means x tells you almost nothing about y, at least in a straight-line way.11Fabric. Simple Linear Regression: Residuals, Variance Estimation, and R² – STAT 212, Ch. 1 (Part A) – Study Notes In simple regression, R-squared is just the correlation r squared, so r = 0.7 gives R-squared of 0.49.12Wikipedia. Coefficient of determination13PubMed Central. Statistics review 7: Correlation and regression

With an R-squared of 0.49 for exam score on hours studied, about 49% of the differences in scores between students line up with differences in study hours. The other 51% comes from things the line does not capture, such as sleep, prior knowledge and luck. Taking the square root gives r of 0.7 in size, and the sign of the slope tells you whether r is positive or negative.

R-squared is easy to misread. A low value doesn’t mean the slope is wrong; it means lots of scatter remains. A high value doesn’t prove the straight line is the right shape. What counts as good depends on the field, since human behavior data often sit far lower than physics data. And R-squared says nothing about cause.

Before using the line to predict, check whether the slope is meaningfully different from zero, using a t-test.14Introductory Statistics. What Is Simple Linear Regression and How Does It Work? Software reports a p-value, and a p-value below 0.05 is the usual cutoff for saying the slope isn’t zero.15Calcworkshop. Linear Regression T Test16Real Statistics Using Excel. What Is Simple Linear Regression and How Does It Work? A 95% confidence interval for the slope gives a range of plausible true slopes, and if it excludes zero, the slope is statistically distinguishable from zero.16Real Statistics Using Excel. What Is Simple Linear Regression and How Does It Work?

A tiny p-value says the slope is probably not zero, but it says nothing about how big or useful the slope is. With a very large sample, even a slope too small to matter in practice can produce a very small p-value. So look at the size of the slope and the width of its confidence interval, not just whether p falls below 0.05.

Checking Whether the Line Can Be Trusted

Least squares gives the best straight-line estimates when the errors average zero, have the same spread everywhere, and are unrelated to each other.17Wikipedia. Gauss–Markov theorem The data should come from a random sample, and the relationship should be linear.18Statistics How To. Gauss Markov Theorem & Assumptions The errors don’t need to be bell-shaped for the line itself to be the best estimate.17Wikipedia. Gauss–Markov theorem Bell-shaped errors matter mainly for p-values and confidence intervals.7Statistics Fundamentals. What Is Simple Linear Regression and How Does It Work? The most common mistake is checking y itself for a bell shape, when it’s the residuals that should be checked.19PubMed Central. Common misconceptions held by health researchers when interpreting linear regression assumptions, a cross-sectional study19PubMed Central. Common misconceptions held by health researchers when interpreting linear regression assumptions, a cross-sectional study

Linearity means the average of y changes by a steady amount for each step in x, not that the points fall exactly on a line. Data that rise quickly and then flatten, like skill gained with practice, break this condition even if the overall trend is upward. A straight line fitted to such data predicts too high in some places and too low in others, in a consistent pattern.

Errors are independent when knowing one point’s miss tells you nothing about the next point’s miss. This often fails with data collected over time, such as daily sales, where a high day tends to be followed by another high day. It also fails when points are grouped, such as several students from the same classroom, since they share influences. Ignoring this can make the p-value and confidence interval look more trustworthy than they are.

The main check is a residual plot, which graphs each point’s miss against its predicted value.20StatsNotebook. Residual plots and assumption checking When assumptions hold, the dots look like random scatter with no pattern.20StatsNotebook. Residual plots and assumption checking A curve in the dots means the relationship isn’t straight, and a fan shape means the spread isn’t even.20StatsNotebook. Residual plots and assumption checking

Anscombe’s quartet shows why this matters. Four datasets give the identical regression line and statistics. Plotted, one is a clean line, one is a curve, one has an outlier, and one gets its slope almost entirely from a single far-out point. The numbers alone hid completely different patterns, so look at a plot before trusting the output.

When One Point Pulls the Whole Line

Points far from the pattern, or far out on the x-axis, can distort the regression.21Wikipedia. Cook’s distance An outlier is a point that sits far from the line vertically. A point far out in x has high leverage even if it fits. The dangerous ones combine both, while some outliers barely move the line at all. Cook’s distance measures how much the whole line changes when one point is removed.22Eberly College of Science. 9.5 – Identifying Influential Data Points

When a point is flagged, first check for a typo or measurement error. Don’t delete a real point just because it’s inconvenient. Fit the line with and without it and compare, and report both if the conclusions change. Robust regression methods reduce the pull of outliers to fit the bulk of the data better.23Penn State Department of Statistics. Robust Regression

Why a Regression Line Doesn’t Prove Cause

A slope can’t be read as cause if some other factor could explain the link.24Sociological Methods & Research. Impact of a Confounding Variable on a Regression Coefficient Such a factor is called a confounding variable, and leaving a hidden third factor out biases the slope.25Statistics By Jim. Confounding Variable: Definition & Examples The fixes are random-assignment experiments or measuring the factor and adding it to the model.24Sociological Methods & Research. Impact of a Confounding Variable on a Regression Coefficient Sometimes the factor can’t be measured at all.24Sociological Methods & Research. Impact of a Confounding Variable on a Regression Coefficient

Ice cream sales and drowning rise together, because hot weather drives both. Regressing one on the other gives a real-looking slope, and adding temperature to the model shrinks it.

Direction is also hidden. A regression of y on x gives a slope even if the true story runs the other way, with y influencing x. A line linking exercise and mood cannot tell whether exercise lifts mood or people in good moods exercise more. The math treats both stories alike, so direction has to come from knowing how the data were produced.

When the Relationship Isn’t a Straight Line

The first clue to a curve is usually a bowed pattern in the residual plot or a scatterplot that bends rather than runs straight. A line fitted through a bend tends to miss high in the middle and low at the ends, or the reverse, in a systematic way. Diagnosing the shape first helps you choose a fix.

Taking the logarithm of a variable is a common way to handle a curved relationship.26London School of Economics. Linear Regression Models with Logarithmic Transformations The fitted relationship becomes curved while the model stays linear in its calculation.26London School of Economics. Linear Regression Models with Logarithmic Transformations Transforming can also even out uneven spread.27University of Virginia Library. What Is Simple Linear Regression and How Does It Work? Another option adds a squared x term to fit a bend.28EPsy 8252 Notes. Unit 2: Nonlinearity: Log-Transforming the Predictor

A log suits things like income, prices and population, which often grow by percentages. It turns percentage growth into steady steps, so the slope reads as change per percent. After transforming, check the residual plot again.

Regression Versus Correlation and Multiple Regression

Correlation and the slope always share a sign.5VSNi. Pearson Correlation vs. Simple Linear Regression But correlation has no units and no direction of prediction, while regression gives a usable equation. Correlation runs from -1 to 1, with values near either end meaning points hug a straight line and values near 0 meaning no straight-line pattern. Swapping x and y leaves the correlation unchanged, while the regression line changes. Correlation alone cannot say how much y changes for a one-unit change in x, which is what the slope provides. Multiple regression adds more inputs with the same form: y = β0 + β1×1 + β2×2 + …29Cathie Marsh Institute Working Paper. Multiple Linear Regression It is also the main way to account for a hidden factor you can measure.24Sociological Methods & Research. Impact of a Confounding Variable on a Regression Coefficient