Show Sidebar Hide Sidebar

Exponential Fits

Fitting data with an exponential function

Rat population growth under optimal conditions

Plotly offers free, online tools for analyzing data and making graphs. In this tutorial we’ll show you how to fit exponential curves to your data and explain what that means. Make sure to check out our other tutorials to learn how to fit your data with polynomials, gaussians, and logarithms.

An exponential fit is a method of modeling data with an exponential function. Exponential growth (or decay) occurs naturally in many settings–the growth of bacteria can be modeled with an exponential function, scientists study radioactive decay in order to determine how old dinosaur bones are, and money in a savings account grows exponentially.

There are many theories about the destruction of Easter Island. Dr Terry Hunt at the University of Hawaii hypothesizes that rats may be part of the explanation. His work was featured in an American Scientist article “Rethinking the Fall of Easter Island”. Under ideal conditions, a rat population can double every 47 days. The graph on the right contains data about optimal rat population growth during the first 188 days (about six months). In this tutorial we’ll estimate the population size of a colony of rats living in optimal conditions after three years assuming a single pair of rats to start.

It’s important to remember that the exponential growth model for population has limits. Eventually a population, especially in a closed environment like Easter Island, will deplete resources which will hinder growth. For this example we’re ignoring these issues. If you want to learn more, a nice article in Nature Education discusses both exponential and logistic equations for modeling population growth.

Exponential data falls into two categories: growth and decay. Learn to recognize the shape of these two types of exponential functions and you’ll be analyzing your data in no time!

Exponential growth is characterized by slow initial growth that becomes rapidly faster as time progresses. A picture of exponential growth
Exponential decay begins with a fast (and negative) rate of change, which decreases (in magnitude) with time. A picture of exponential decay

In Plotly, our predefined exponential functions take the form $a+be^{cx}$. If you want to fit your curve with another base, you can use the Define your own fit function option. If you need help, our tutorial on custom fit functions will help. Plotly finds the best exponential fit by choosing coefficients $a$, $b$ and $c$ that minimize the mean squared error. The closer the $R^2$ value is to 1, the better the fit.

Step 1: Make a plot

We have a collection of great tutorials to help you make line graphs, scatter plots, histograms, bar charts, and more. If you need help, you’ll find everything you need on our tutorials page.

You can import files from Google Drive, Dropbox, or Excel for your graphs. You’ll find more details in our “How to Enter Data in the Grid” tutorial. Button to upload data to Plotly
In an optimal world (for rodents), a rat population can double in size every 47 days. Starting with two rats on day zero, we’ll have four rats on day 47, 8 rats on day 94, and so on.

You can enter this data in Plotly’s grid directly, or you can Fork & edit it from

https://plot.ly/~mariahh/63
Picture of optimal rat population growth data
To make a scatter plot, choose Scatter plots from the MAKE A PLOT menu.

Plotly will automatically select the first column of data to be $x$ values, and the second column to be $y$ values. In our case, this is exactly what we want.

Click on the blue Scatter plot button in the sidebar to make your scatter plot. Your plot will open in a new tab.
Make a scatter plot with Plotly

Step 2: Exponential regression

Once you’ve made a scatter plot (here, using the rat population data for the first 6 months), you can decide on a best fit function. The scatter plot shows a rapidly increasing rate of change, so an exponential fit is a good choice.

To find the curve of best fit, click FIT DATA in the toolbar above your graph.

When you click FIT DATA, you’ll see the Fitting to trace popover open. Select Add fit to this trace.
Fitting data with Plotly
Select Exponential from the drop-down menu. Menu to select an exponential fit
You’ll be given the option to guess the coefficients $a$, $b$ and $c$, but this isn’t required. Option to guess coefficients
Bonus: the predefined exponential function take the form $a+be^{cx}$. If you want to fit your curve with another base, you can use the Define your own fit function option.

You can use $x$ as a variable, and pick your other parameters. You’ll need to enter an initial guess for Plotly’s regression to get started.
Using another base with a custom fit function
The Advanced tab offers even more flexibility. You can incorporate error data into your fit, restrict the fit to a subset of your data, extend the domain, and change the number of points in the output fit.

Because we want to know how many rats could be in our colony after 3 years, we’ll need to select Plot fit curve over a specified x-range.
Advanced fitting options tab
Because the units on our $x$-axis are days, we’ll use the fact that there are 1095 days in 3 years to pick the domain for the exponential fit.

Now click Run this fit.
Using advanced options to plot an over an extended domain
By selecting Add results as plot annotation, your graph will include a best fit equation and $R^2$ value.

We can see that the rat population, left unchecked, could reach approximately 20 million in 3 years! The reality on Easter Island would have been a bit different–when important factors like food are considered, we would expect approximately 75 rats per acre at most. That means a little more than 3 million rats on Easter Island. Easily enough to be responsible for the deforestation.
Run the fit and add results as annotation
To close the Fitting to trace popover, click the X in the upper-right corner. We can drag the annotation and even style our graph with Plotly’s online tools. You might want to check out the TRACES button. Close the Fitting to trace popover and style with options in TRACES

Love what you made? You can share, print, download, and embed your plots.

You can find the graph used in this tutorial, and the underlying data at:

https://plot.ly/~mariahh/63

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.