ThisCalculator

Everyday

Linear and Exponential Regression Calculator

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

This calculator performs both linear regression (y = a + bx) and exponential regression (y = a·ebx or y = a·bx) on a set of (x, y) data points you enter. You input paired x and y values, and the calculator returns the regression coefficients, the correlation coefficient (r), and the coefficient of determination (r²) for both models, allowing you to compare which fits your data better.

Formula

Linear regression fits the equation y = a + bx using the least squares method. The slope b and intercept a are calculated as:

  • b = [n·Σ(xy) − Σx·Σy] / [n·Σ(x²) − (Σx)²]
  • a = (Σy − b·Σx) / n

where n is the number of data points, Σ denotes summation over all points, x and y are the raw data values. The coefficient of determination r² is the square of the Pearson correlation coefficient r, which measures how well the linear model explains the variability of y.

Exponential regression fits the equation y = a·ebx (or equivalently y = a·bx with b = eb). To linearize, take the natural logarithm of both sides: ln(y) = ln(a) + b·x. Then apply linear regression to the transformed data (x, ln(y)). The slope of that regression gives b, and the intercept gives ln(a), so a = eintercept. The r² for the exponential model is computed on the transformed (ln(y)) values, indicating how well the exponential curve fits the original data on a log scale.

Worked Example

Using the default data: x = 1, 2, 3, 4, 5 and y = 2.1, 4.3, 8.2, 16.1, 32.0.

Linear:

  • n = 5, Σx = 15, Σy = 62.7, Σxy = 1·2.1 + 2·4.3 + 3·8.2 + 4·16.1 + 5·32.0 = 2.1 + 8.6 + 24.6 + 64.4 + 160 = 259.7
  • Σx² = 1 + 4 + 9 + 16 + 25 = 55
  • b = (5·259.7 − 15·62.7) / (5·55 − 225) = (1298.5 − 940.5) / (275 − 225) = 358 / 50 = 7.16
  • a = (62.7 − 7.16·15) / 5 = (62.7 − 107.4) / 5 = −44.7 / 5 = −8.94

So the linear fit is y = −8.94 + 7.16x. The r² for this data is approximately 0.966, meaning about 96.6% of the variation in y is explained by the linear model.

Exponential:

  • First compute ln(y): ln(2.1) ≈ 0.7419, ln(4.3) ≈ 1.4586, ln(8.2) ≈ 2.1041, ln(16.1) ≈ 2.7788, ln(32.0) ≈ 3.4657
  • Σx·ln(y) = 1·0.7419 + 2·1.4586 + 3·2.1041 + 4·2.7788 + 5·3.4657 = 0.7419 + 2.9172 + 6.3123 + 11.1152 + 17.3285 = 38.4151
  • Σln(y) = 0.7419 + 1.4586 + 2.1041 + 2.7788 + 3.4657 = 10.5491
  • b = (5·38.4151 − 15·10.5491) / (5·55 − 225) = (192.0755 − 158.2365) / 50 = 33.839 / 50 = 0.67678
  • a = exp((10.5491 − 0.67678·15) / 5) = exp((10.5491 − 10.1517) / 5) = exp(0.3974 / 5) = exp(0.07948) ≈ 1.0827

The exponential fit is y ≈ 1.083·e0.6768x. The r² for the exponential model is about 0.999, which is higher than the linear r², indicating the exponential model fits this data better.

When to Use Linear vs. Exponential Regression

Use linear regression when the relationship between x and y appears to be a straight line: as x increases by a constant amount, y changes by a roughly constant amount. Examples include converting temperature (Celsius to Fahrenheit), simple cost calculations, or speed vs. time at constant acceleration.

Use exponential regression when the rate of change is proportional to the current value, meaning y grows or decays by a constant percentage per unit of x. Common examples include population growth, radioactive decay, compound interest, bacterial growth, and depreciation. A quick visual test: if a plot of ln(y) vs. x looks roughly linear, an exponential model is appropriate.

When in doubt, run both models and compare the r² values. The model with the higher r² (closer to 1) generally fits the data better, but be cautious: r² alone doesn’t tell you if the model is appropriate—always check the residual plots or the context of your data.

How to Read the Results

The slope (b) in linear regression tells you the average change in y for a one-unit increase in x. The intercept (a) is the predicted y when x = 0. For exponential regression, a is the initial value (y at x = 0), and b is the continuous growth rate. If you prefer the form y = a·bx, convert b to bexp = eb. For example, if b = 0.6768, then bexp = e0.6768 ≈ 1.968, meaning the quantity multiplies by about 1.968 (almost doubles) for each unit increase in x.

R-squared (r²) is the proportion of variance in y explained by the model. An r² of 0.99 means 99% of the variation is explained, leaving 1% unexplained. However, r² alone doesn’t indicate whether the model is appropriate; a high r² can occur even with a wrong model if the data is limited or has outliers. Always plot your data and the fitted curve to visually check the fit.

Common Mistakes and Limitations

  • Unit mix-ups: Ensure x and y are in consistent units. If you mix meters and feet, the coefficients will be meaningless.
  • Zero or negative y values in exponential regression: The natural logarithm is undefined for y ≤ 0. If your data contains zero or negative y values, exponential regression cannot be applied directly. Consider adding a constant to shift the data, or use a different model.
  • Overfitting: Adding more terms (like polynomial regression) always increases r², but may not generalize well. Stick to the simplest model that fits the data reasonably.
  • Extrapolation: Regression models are only valid within the range of the observed x values. Predicting outside that range can be wildly inaccurate, especially for exponential models.
  • Outliers: A single outlier can heavily influence the regression line, especially with small datasets. Identify and investigate outliers before trusting the model.

How to Choose the Best Model

Start by plotting your data. Look at the shape: if the points roughly form a straight line, linear regression is appropriate. If they curve upward or downward like a hockey stick or a decay curve, try exponential. To confirm, plot ln(y) vs. x: if that looks linear, exponential is a good fit.

After fitting both, compare the r² values. The model with the higher r² is generally better, but also consider the residual plots—if residuals show a pattern (like a curve), the model is missing something. For small datasets, r² can be misleading, so use adjusted r² if available.

Also consider the practical context: if your data represents growth that compounds (like population or investment), exponential is theoretically justified. If it represents a steady trend (like a constant speed), linear is more appropriate. Never choose a model solely based on r² without understanding the underlying process.

Frequently Asked Questions

What is the difference between linear and exponential regression?

Linear regression fits a straight line (y = a + bx) where the change in y per unit x is constant. Exponential regression fits a curve (y = a·ebx) where the change in y per unit x is proportional to the current y, meaning y grows or decays by a constant percentage. Linear is for constant rate of change, exponential for constant percent change.

Can exponential regression handle negative y values?

No, because the natural logarithm of a negative number or zero is undefined. If you have negative y values, you cannot apply exponential regression directly. You could add a constant to make all y positive, but that changes the model interpretation. Alternatively, consider a different model like polynomial or power regression.

How do I know which regression model to use for my data?

Plot your data first. If it looks like a straight line, use linear. If it curves and the rate of growth increases or decreases exponentially, try exponential. You can also compare the r² values from both models—the one with higher r² usually fits better. But always consider the context of your data and whether an exponential relationship makes theoretical sense.

What does R-squared mean in regression?

R-squared (r²) is the coefficient of determination. It represents the proportion of the variance in the dependent variable (y) that is predictable from the independent variable (x). An r² of 1 means the model perfectly explains all the variation, while 0 means it explains none. Higher r² generally indicates a better fit, but it doesn’t prove causation.

Can I use this calculator for exponential decay?

Yes. Exponential decay has a negative b value in the equation y = a·ebx. The calculator will output a negative b if your data is decreasing. For example, radioactive decay or cooling processes often follow exponential decay. Just enter your data and the calculator will handle it.

Why do I get different results than Excel or a graphing calculator?

Different tools may use slightly different algorithms or rounding. Also, some calculators use the form y = a·bx instead of y = a·ebx. To compare, convert: bexp = eb. Also, check that you entered the data correctly and that you’re comparing the same type of regression (e.g., linear vs. exponential).

Related

Formula used
in x | X values (comma-separated) | - | 1, 2, 3, 4, 5 | 0
in y | Y values (comma-separated) | - | 2.1, 4.3, 8.2, 16.1, 32.0 | 0
out lin_slope | Linear slope (b) | - | (count(x)*sum(x*y)-sum(x)*sum(y))/(count(x)*sum(x^2)-sum(x)^2) | 4
out lin_intercept | Linear intercept (a) | - | (sum(y)-lin_slope*sum(x))/count(x) | 4
out lin_r2 | Linear R-squared | - | ((count(x)*sum(x*y)-sum(x)*sum(y))/sqrt((count(x)*sum(x^2)-sum(x)^2)*(count(x)*sum(y^2)-sum(y)^2)))^2 | 4
out exp_a | Exponential coefficient (a) | - | exp((sum(ln(y))-exp_b*sum(x))/count(x)) | 4
out exp_b | Exponential rate (b) | - | (count(x)*sum(x*ln(y))-sum(x)*sum(ln(y)))/(count(x)*sum(x^2)-sum(x)^2) | 4
out exp_r2 | Exponential R-squared | - | ((count(x)*sum(x*ln(y))-sum(x)*sum(ln(y)))/sqrt((count(x)*sum(x^2)-sum(x)^2)*(count(x)*sum(ln(y)^2)-sum(ln(y))^2)))^2 | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.