This account already has saved data. Do you want to keep this device's data, or use your account's saved data?
Appearance
Unit System
Temperature Format
Time Format
Least Squares Regression
Line of Best Fit
Line of Best Fit
Your Recent & Past Results
Restored a past calculation.
Compare Calculations
Side-by-Side Comparison
A comparison of your calculations' results.
Downloads
Includes your inputs and results for this calculation, plus any additional calculations you've compared.
Share & Print
The link includes your inputs and results, so anyone who opens it sees this exact calculation.
Fitting a Line Through Scattered Data Points
Least squares regression finds the single straight line that best fits a scatter of data points. Enter a list of x, y pairs — one per line — and this calculator finds the line’s slope and intercept, plus how strongly the points actually follow that line.
The Formula
m=n∑x2−(∑x)2n∑xy−∑x∑yb=n∑y−m∑x
where m is the slope, b is the intercept, and n is the number of data points — together they describe the line y=mx+b that minimizes the total squared distance from every point to the line.
Worked Example
Fitting a line through (1, 1), (2, 2), and (3, 4):
m=3(14)−623(17)−6(7)=42−3651−42=69=1.5
b=37−1.5(6)=37−9=−0.667 — so the fitted line is y=1.5x−0.667, with a correlation coefficient of about 0.98.
Key Factors to Consider
A strong correlation coefficient doesn’t necessarily mean x actually causes y. Two
variables can be strongly correlated because one genuinely influences the other, because both
are driven by a third factor, or purely by coincidence in a small dataset — correlation
describes the strength of a linear relationship, not the reason behind it.
This method assumes the true relationship is linear, which isn’t always the right
assumption. If a scatter of points actually follows a curve, forcing a straight line through
it can produce a technically “best fit” line that still describes the data poorly — plotting
the points visually before trusting the fit is good practice.
A single unusual point (an outlier) can disproportionately pull the fitted line toward
it. Because least squares minimizes SQUARED distances, a point far from the general trend
contributes much more to the fit than a point close to it — a small dataset with one extreme
outlier is especially sensitive to this.
More data points generally produce a more reliable fit, all else equal. A line fit through
only 3-4 points (as in the worked example) can look convincing but carries much more
uncertainty than the same relationship measured across dozens of points — correlation strength
alone doesn’t capture how much data actually backs up the fit.
Common Mistakes
Treating a high correlation coefficient as proof of causation. A strong r-value only shows
the points cluster tightly around a line — it says nothing about whether one variable actually
causes changes in the other.
Fitting a straight line to data that’s actually curved. Least squares always returns a
slope and intercept, even when a linear fit badly describes the underlying pattern — plot the
points first, or check whether the correlation coefficient is surprisingly low, before trusting
the result.
Using too few data points and treating the fit as reliable. A line through just 3-4 points
can look convincing but carries far more uncertainty than the same relationship measured across
dozens of points.
Letting a single outlier dominate the fit without noticing. Because least squares minimizes
squared distances, one far-off point can pull the whole line toward it — worth checking whether
removing an unusual point changes the result substantially.
Useful to Know
Need to estimate a value between two known points instead of fitting a trend line through many?
The Linear Interpolation Calculator calculator covers that more direct case.
Want to see how one specific value compares to the overall spread of a dataset? The
Z-Score Calculator calculator measures exactly that.
Working with the same list of numbers for broader summary statistics? The
Statistics Calculator calculator covers mean, median, and standard deviation.
Ajustar una Línea a Puntos de Datos Dispersos
La regresión por mínimos cuadrados encuentra la única línea recta que mejor se ajusta a una
dispersión de puntos de datos. Ingresa una lista de pares x, y — uno por línea — y esta
calculadora encuentra la pendiente e intersección de la línea, además de qué tan estrechamente
siguen los puntos realmente esa línea.
La fórmula
m=n∑x2−(∑x)2n∑xy−∑x∑yb=n∑y−m∑x
donde m es la pendiente, b es la intersección, y n es el número de puntos de datos —
juntos describen la línea y=mx+b que minimiza la distancia total al cuadrado de cada punto
a la línea.
Ejemplo resuelto
Ajustando una línea a través de (1, 1), (2, 2), y (3, 4):
m=3(14)−623(17)−6(7)=42−3651−42=69=1.5
b=37−1.5(6)=37−9=−0.667 — así que la línea ajustada es y=1.5x−0.667, con un coeficiente de correlación de aproximadamente 0.98.
Factores Clave a Considerar
Un coeficiente de correlación fuerte no significa necesariamente que x realmente cause y. Dos
variables pueden estar fuertemente correlacionadas porque una realmente influye en la otra, porque
ambas están impulsadas por un tercer factor, o simplemente por coincidencia en un conjunto de
datos pequeño — la correlación describe la fuerza de una relación lineal, no la razón detrás de
ella.
Este método asume que la relación real es lineal, lo cual no siempre es la suposición
correcta. Si una dispersión de puntos en realidad sigue una curva, forzar una línea recta a
través de ella puede producir una línea técnicamente de “mejor ajuste” que aún así describe mal
los datos — graficar los puntos visualmente antes de confiar en el ajuste es una buena práctica.
Un solo punto inusual (un valor atípico) puede tirar desproporcionadamente de la línea ajustada
hacia él. Debido a que los mínimos cuadrados minimizan distancias AL CUADRADO, un punto alejado
de la tendencia general contribuye mucho más al ajuste que un punto cercano a ella — un conjunto
de datos pequeño con un valor atípico extremo es especialmente sensible a esto.
Más puntos de datos generalmente producen un ajuste más confiable, con todo lo demás igual.
Una línea ajustada a través de solo 3-4 puntos (como en el ejemplo resuelto) puede parecer
convincente pero conlleva mucha más incertidumbre que la misma relación medida a través de
decenas de puntos — la fuerza de la correlación por sí sola no captura cuántos datos realmente
respaldan el ajuste.
Errores Comunes
Tratar un coeficiente de correlación alto como prueba de causalidad. Un valor r fuerte solo
muestra que los puntos se agrupan estrechamente alrededor de una línea — no dice nada sobre si
una variable realmente causa cambios en la otra.
Ajustar una línea recta a datos que en realidad son curvos. Los mínimos cuadrados siempre
devuelven una pendiente e intersección, incluso cuando un ajuste lineal describe mal el patrón
subyacente — grafica los puntos primero, o verifica si el coeficiente de correlación es
sorprendentemente bajo, antes de confiar en el resultado.
Usar muy pocos puntos de datos y tratar el ajuste como confiable. Una línea a través de
solo 3-4 puntos puede parecer convincente pero conlleva mucha más incertidumbre que la misma
relación medida a través de decenas de puntos.
Dejar que un solo valor atípico domine el ajuste sin notarlo. Debido a que los mínimos
cuadrados minimizan distancias al cuadrado, un punto muy alejado puede arrastrar toda la línea
hacia él — vale la pena comprobar si eliminar un punto inusual cambia sustancialmente el
resultado.
Útil Saber
¿Necesitas estimar un valor entre dos puntos conocidos en lugar de ajustar una línea de
tendencia a través de muchos? La Calculadora de Interpolación Lineal cubre ese caso más
directo.
¿Quieres ver cómo se compara un valor específico con la dispersión general de un conjunto de
datos? La Calculadora de Puntuación Z mide exactamente eso.
¿Trabajas con la misma lista de números para estadísticas resumidas más amplias? La
Calculadora de Estadística cubre la media, la mediana, y la desviación estándar.
Least squares regression finds the single straight line that best fits a scatter of data points, by minimizing the sum of the squared vertical distances between each point and the line. It's the standard method for describing a linear relationship between two variables.
What do the slope and intercept mean?
The slope tells you how much y changes for every 1-unit increase in x -- a slope of 2 means y goes up by 2 each time x goes up by 1. The intercept is the line's predicted y value when x is 0, which is where the line crosses the vertical axis.
What does the correlation coefficient (r) tell me?
The correlation coefficient ranges from -1 to 1 and measures how tightly the points cluster around the fitted line. A value near 1 means a strong positive relationship (as x goes up, y reliably goes up too), near -1 means a strong negative relationship, and near 0 means little to no linear relationship at all. R-squared (r²) is simply r multiplied by itself, and is often read as "the percentage of the variation in y that's explained by x."
Does a strong correlation mean x causes y?
No — correlation only measures how strongly two variables move together, not why. A strong correlation can reflect real causation, a shared underlying cause affecting both variables, or simple coincidence, especially in a small dataset. Don't treat a high correlation coefficient alone as proof of a causal relationship.
What if my data doesn't actually follow a straight line?
Least squares regression always fits a straight line, even to data that genuinely follows a curve — it will still return a slope, intercept, and correlation coefficient, but they may describe the relationship poorly. Plotting your points first, or checking whether the correlation coefficient is unexpectedly low, can flag when a linear fit is the wrong tool for your data.
We use cookies for analytics and ads to help support this free site. You can accept all, or decline and we'll only use what's needed for the site to work.