unspurious.calculators

Core inference · Curve fitting

Nonlinear Regression Calculator

Fit a curve, not just a line. Paste your x and y data and choose a model — quadratic, cubic, exponential, power or logarithmic — to get the fitted equation, the R², predictions and a scatter-and-curve plot. With a straight word about the two ways curve fitting deceives: chasing R² with ever-bendier curves, and trusting a fit beyond the data it was built on.

Exponential and power models need positive y; power and logarithmic need positive x. Invalid points are dropped with a note.

Result

In plain English

Regression draws the curve of a chosen shape that comes closest to your points — “closest” meaning the sum of squared vertical gaps is as small as possible. Picking the shape is your decision, and the wrong shape can fit the numbers you have while being nonsense everywhere else. The R² tells you how tightly the curve hugs the data, not whether you picked the right curve.

least squares
The fitting rule: choose the coefficients that minimise the total squared distance between the curve and the points.
R² (coefficient of determination)
The share of the variation in y the curve accounts for, from 0 to 1. Higher is a tighter fit — but adding bends almost always raises it, even when they are fitting noise.
polynomial vs transformed fits
Quadratic and cubic are fitted directly. Exponential, power and logarithmic are fitted by taking logs and running a straight-line fit, so they minimise error in log-space — a standard shortcut, not the exact nonlinear least-squares solution.
overfitting
A wigglier model (higher-degree polynomial) can pass closer to every point yet capture the noise rather than the signal, predicting worse on new data.
extrapolation
Curves diverge fast outside the range of your data. A fit that looks perfect between x = 1 and 10 can be wildly wrong at x = 20.

Frequently asked

How do I choose between a quadratic, exponential or power fit?

Let the mechanism guide you, not the R². Use an exponential when something grows by a roughly constant percentage per step (compound interest, unchecked populations); a power law when y scales with a power of x (area with length, many physical laws); a quadratic for a single hump or a constant-acceleration process. Then check that the residuals look patternless. A higher R² alone is a weak reason — a more flexible model nearly always wins on R² while predicting new data worse.

Does a higher R² mean a better model?

Not necessarily. R² only measures how closely the curve fits the data you already have, and it rises automatically as you add terms — a cubic can never have a lower R² than a quadratic on the same data. A model can post a near-perfect R² by bending to fit noise (overfitting) and then predict new points badly. Judge a model by whether its shape is justified, whether the residuals are patternless, and ideally how it does on held-out data.

How does exponential regression work here?

For y = a·e^(bx), the calculator takes the natural log of both sides — ln y = ln a + b·x — which is linear in x, fits that straight line by least squares, then transforms back. The same log trick fits power (y = a·x^b, log both x and y) and logarithmic (y = a + b·ln x) models. It is the standard quick method, though because it minimises error in log-space it can differ slightly from a full nonlinear least-squares fit.

What is overfitting, and how do I avoid it?

Overfitting is when a model bends to match the noise in your particular sample rather than the underlying pattern, so it fits the data you have beautifully but predicts new data badly. The warning signs are a high-degree curve, a near-perfect R², and wild swings between or beyond the points. Avoid it by choosing the simplest shape the mechanism justifies, checking that the residuals look patternless, and — ideally — judging the fit on held-out data the model never saw.