Skip to content
ihateDesmos

Regression calculator

Enter or paste your data, write the model you want with ~ instead of =, and the calculator fits it. Every parameter comes with a standard error, and you can show the residuals and a 95% confidence band for the fitted curve.

123456710200
Open in calculator
Seven data points with an exponential fit (R² = 0.99995) and a linear fit (R² = 0.864) for comparison.

How to use the regression calculator

  1. 1
    Add a table from the + menu and type or paste your data into the columns x1 and y1. You can also import a CSV file.
  2. 2
    Type the model with ~: y1 ~ m x1 + b for a line, y1 ~ a x1^2 + b x1 + c for a quadratic, y1 ~ a e^(b x1) for exponential.
  3. 3
    Read the fitted parameters, their standard errors, R² and RMSE under the row.
  4. 4
    Turn on the 95% band to see the uncertainty in the fitted curve, or Residuals to check the model.

How the fit is computed

Linear models (any model that is linear in its parameters, including polynomials) are solved exactly by least squares using a QR decomposition. That is more accurate than the textbook normal equations, which square the condition number and lose digits on badly scaled data.

Nonlinear models, such as a e^(bx) or a logistic curve, are fitted by the Levenberg–Marquardt algorithm. It minimises the same sum of squared residuals, starting from automatic initial guesses. The exponential is fitted directly rather than by taking logarithms, so large and small values are weighted the same.

Reading the output

  • Parameters ± standard error. The ± is one standard error. Roughly, the true value is within two standard errors 95% of the time.
  • R² is the fraction of the variation in y that the model explains. Close to 1 is a tight fit, but a high R² does not prove the model is right.
  • RMSE is the typical size of a residual, in the units of y.
  • The 95% band shows where the true curve plausibly lies, given the data. It is narrowest near the middle of the data and widens at the ends.
  • Residuals should look like random scatter around zero. A curved pattern means the model is missing something.

Choosing a model

Start from what you know about the process. Constant rates of change suggest a line, constant percentage growth an exponential, and growth that levels off a logistic curve. Then check the residuals. Adding parameters always raises R², so prefer the simplest model whose residuals look random.

Examples to try

24681010200
Linear fit
y1 ~ m x1 + b
A straight line through nine points.
Open this example
2468510150
Quadratic fit
y1 ~ a x1^2 + b x1 + c
A projectile-like rise and fall.
Open this example
246810125100
Logistic fit
y1 ~ L/(1 + e^(-k(x1 - h)))
Growth that levels off at a carrying capacity L.
Open this example

Frequently asked questions

How do I do a linear regression?
Put your data in a table, then type y1 ~ m x1 + b. The calculator shows m and b with their standard errors, R² and RMSE.
Can it fit exponential and other nonlinear models?
Yes. Write any model with ~, such as y1 ~ a e^(b x1). Nonlinear models are fitted with the Levenberg–Marquardt algorithm.
What does R² mean?
The fraction of the variation in y explained by the model, from 0 to 1. A high R² alone does not show the model is appropriate; check the residuals too.
Can I import data from a spreadsheet?
Yes. Paste columns into a table or use Import CSV.
What is the confidence band?
A 95% confidence band for the fitted curve: the region where the true curve plausibly lies given the data and the model.

Related tools and guides

Try the regression calculator

It opens instantly, with no account and nothing to install.

Open the calculator