Curve Fitting Calculator
Paste x and y values and fit linear, polynomial (degree 2–6), exponential, logarithmic and power curves in one go. You get each equation with R², adjusted R², RMSE, AIC and AICc side by side, a plot with every curve, residual diagnostics, parameter standard errors and predictions for new x values. Free, no sign-up; everything runs in your browser.
0 values
0 values
Enter at least four (x, y) pairs, with at least three different x values.
How to Use the Curve Fitting Calculator
- 1. Enter your data. Type two lists in matching order, or one "x, y" pair per line. Four or more points with at least three different x values are needed; more is better.
- 2. Choose the models. Tick the curves to compare. Logarithmic and power models need every x above 0; exponential and power models need every y above 0. A model that cannot be fitted says why.
- 3. Pick the fitting method for exponential and power curves. Non-linear least squares on the original y gives the best fit to your actual values. The transformed option fits a straight line through ln y, as spreadsheet trendlines do.
- 4. Compare and check. Read the table, then the plot and residuals of the model you are considering: the best number means little if the curve's shape is wrong. Use the prediction box for new x values.
The Curves
| Model | Equation | Typical use |
|---|---|---|
| Linear | y = a₀ + a₁x | Steady change |
| Polynomial, degree d | y = a₀ + a₁x + … + a_dx^d | A smooth curve with bends; d − 1 turning points at most |
| Exponential | y = a·e^(bx) | Growth or decay at a constant percentage rate |
| Logarithmic | y = a + b·ln x | Rapid change that levels off |
| Power | y = a·x^b | Scaling laws; b is the elasticity |
Every polynomial is fitted by QR decomposition on a centred, rescaled x, so a degree-6 fit to calendar years (1990–2020) is as accurate as one to 0–1, and predictions use that stable form. The expanded coefficients shown in the equation can still lose digits to cancellation when x is large and far from zero, and the page warns you when that happens. Spreadsheet trendline equations, which round coefficients to a few digits, cannot reproduce high-degree curves over year-sized x values for the same reason.
Why the Method Matters for Exponential and Power Fits
A transformed fit takes ln y and finds the least-squares straight line, then converts back. That minimises errors on the log scale, which weights small values heavily and big ones lightly. A non-linear fit minimises the squared errors in y itself, which is usually what you care about. The two give different parameters for the same data, and different R² values. This calculator reports R² on the original y for every model, so they can be compared fairly, and, for a transformed fit, the log-scale R² a spreadsheet would show.
Worked Example
The example loads the classic 50 car-braking measurements (R's cars data): speed in mph against stopping distance in feet. Six models, fitted on the original scale:
| Model | R² | RMSE | AICc | Δ AICc |
|---|---|---|---|---|
| Power: y = 0.5897 x^1.5493 | 0.6654 | 15.06 | 417.59 | 0 |
| Exponential: y = 9.4045 e^(0.0917x) | 0.6649 | 15.07 | 417.66 | 0.07 |
| Quadratic | 0.6673 | 15.18 | 419.66 | 2.07 |
| Linear: y = −17.58 + 3.932x | 0.6511 | 15.38 | 419.68 | 2.09 |
| Cubic | 0.6732 | 15.20 | 421.25 | 3.66 |
| Logarithmic | 0.5607 | 17.26 | 431.19 | 13.61 |
R² creeps up with every polynomial term — the cubic scores 0.6732 and a degree-6 polynomial 0.6888 — but AICc, which charges for each parameter, ranks the two-parameter power and exponential curves first. The power curve also has a sensible meaning: braking distance grows roughly as speed to the power 1.5 (b = 1.55, SE 0.19), between the linear and squared relationships physics suggests. The top models are within about 2 AICc points of each other, so the data cannot separate them; prefer the one that makes sense. Fitted as a transformed power curve instead, the log-scale R² is 0.7331 but the original-scale R² falls to 0.6583.
Choosing a Model Sensibly
- Start with the plot, then the residuals. A pattern in the residuals means the shape is wrong.
- Use AICc rather than R² to compare models with different numbers of parameters. AICc is only comparable between models fitted to the same y values. Differences under about 2 are not meaningful.
- Prefer theory. If you know the process (compound growth, a scaling law), use the matching model even if another scores slightly better.
- Keep polynomial degrees low. Beyond degree 3 or 4 a polynomial usually chases noise and swings wildly outside the data. Don't extrapolate with one.
Frequently Asked Questions
- How do I choose the best-fitting curve?
- Plot the data and each curve, check that the residuals scatter evenly around zero, and compare AICc across models. R² alone always prefers the model with the most parameters. Then ask whether the winner makes sense for the process you are studying and whether you will use it only between your smallest and largest x.
- Why is my exponential R² different from Excel's?
- Excel's exponential trendline fits a straight line through ln y and reports R² for that log-scale fit. A non-linear least-squares fit minimises errors in y itself and its R² is measured on y. This calculator can do either, and shows the log-scale R² for the transformed option and the original-scale R² for all models so the comparison is fair.
- What degree of polynomial should I use?
- Use the lowest degree that captures the shape you see, usually 2 or 3. Each added degree lets the curve bend once more and fit noise; R² rises but predictions get worse. You need at least degree + 2 data points, and many more for a reliable fit.
- Why can't I fit a logarithmic, power or exponential model to my data?
- The logarithm is defined only for positive numbers. A logarithmic or power model needs every x above 0, and an exponential or power model needs every y above 0, because the fit works through ln y or ln x. Shift the data (for example, measure time from 1 instead of 0) only if that is meaningful for your problem.
- What do AIC and AICc mean?
- AIC balances fit against complexity: it is −2 times the log-likelihood plus twice the number of parameters (counting the error variance). AICc adds a correction that matters when n is small relative to the parameter count. Lower is better, and only differences matter. The values here use R's definition, so they match R's AIC for the same model.
- Can I use the fitted equation to predict outside my data?
- Only with great care. Every curve here is an empirical description of the range you measured. Polynomials can swing wildly just beyond the data, and an exponential can explode. The prediction box warns you when the new x lies outside the observed range.