Mountains during sunset representing logarithmic regression
Outlier Articles Home

Statistics

Calculating Logarithmic Regression Step-By-Step

08.01.2023 • 6 min read

Sarah Thomas

Subject Matter Expert

Learn about logarithmic regression and the steps to calculate it. We’ll also break down what a logarithmic function is, why it’s useful, and a few examples.

In This Article

  1. What Is a Logarithm?

  2. What Is a Logarithmic Regression?

  3. When Do We Use Logarithmic Regressions?

  4. 3 Types of Logarithmic Regressions

  5. Interpreting Regression Coefficients for Different Logarithmic Regressions

  6. 3 Steps To Calculate Logarithmic Regression

  7. Logarithmic Regression Solved Example

Have you ever wondered how scientists and mathematicians determine the relationship between two variables that don't appear to have a linear relationship? Enter logarithmic regression, a powerful data analysis tool that can help us make sense of complex data.

In this article, we'll explore the basics of logarithmic regression, including how it works, when to use it, and how to interpret the results.

What Is a Logarithm?

A logarithm is a mathematical function that tells you the power to which a base number, bb, needs to be raised to produce a given value.

logb(bx)=x\log{_b(b^x)}=x

For example, if you want to know the power to which the number 3 needs to be raised to produce the number 81, you would find log3(81)=4log_3(81)=4. In this case, the log function tells you that 3 must be raised to the power of 4 to get 81.

Logarithmic functions are an inverse function of exponential functions.

Commonly Used Based Numbers

When working with logarithms, you’ll often run into logarithmic functions that use the irrational number ee—also known as Euler’s number—or the number 10 as base numbers.

Natural Logarithms

A logarithm that uses e as a base number is called a natural logarithm. Natural logarithms are often written as ln(x) instead of logexlog_ex. Similar to the general form of logarithms, if logea=blog_ea=b, then =.

Common Logarithms

A logarithmic function that uses 10 as the base number is called a base 10 logarithm or a common logarithm.

What Is a Logarithmic Regression?

Regression is a statistical method we use to study the relationship between a dependent variable, Y, and one or more independent variables, X1nX_{1\sim n}. The dependent variable might also be called a response variable, and the independent variables are often called predictor variables.

The most basic form of regression is a linear regression, where the relationship between the dependent and independent variables is linear i.e., the relationship can be modeled using a straight line.

When the relationship between variables in your data is non-linear, we need to use a nonlinear regression or a modified version of the linear regression model. A logarithmic regression is a modified linear regression that includes one or more logged variables, where “logged variable” simply means taking the logarithm of a variable.

When Do We Use Logarithmic Regressions?

Logarithmic regressions come in handy when your independent and dependent variables follow a nonlinear relationship matching the pattern of decelerating growth or decay. If your dependent variable increases or decreases rapidly at first as the independent variable decreases, but the rate of that increase or decrease gradually slows, you should consider using a logarithmic regression.

Graphs showing decelerating decay and decelerating Growth

Using logged variables in your regression lets you capture the non-linear relationship between your variables while maintaining a regression model that is linear in the parameters—or regression coefficients—of the model.

Another case to use a logged variable is when you are dealing with a variable highly skewed (to the right) and follows a distribution called a log-normal distribution. By performing a log transformation on a highly skewed variable, you can convert the variable into one with an approximately normal distribution. In general, if a variable xx follows a log-normal distribution, then the log of that variable would follow a normal distribution.

3 Types of Logarithmic Regressions

Three types of logarithmic regressions exist. In each type, you take the natural log, ln(x), of one or more of the variables in the regression equation.

1. Linear-log model

In a linear-log model, you perform a log transformation on the independent variable.

Yi=α+βln(Xi)+ϵiY_{i}=\alpha + \beta\ln{(X_{i})}+\epsilon_{i}

2. Log-linear models

In a log-linear model, you perform a log transformation on the dependent variable.

ln(Yi)=α+βXi+ϵi\ln(Y_{i})=\alpha + \beta X_{i}+\epsilon_{i}

3. Log-log models

In a log-log model, you perform a log transformation on both the dependent and independent variables.

ln(Yi)=α+βln(Xi)+ϵi\ln(Y_{i})=\alpha + \beta\ln{(X_{i})}+\epsilon_{i}

Interpreting Regression Coefficients for Different Logarithmic Regressions

In a simple linear regression, the regression coefficient gives us the estimated change in Y that results from a one-unit change in the independent variable X. The coefficient, in this case, is measured in units of Y, so if equals 3 and Y is measured in dollars, you would interpret the coefficient as: a one-unit increase in X results in a $3.00 increase in Y.

Simple Linear Regression Model

yi^=α^+β^Xi\hat{y_{i}}=\hat{\alpha} + \hat{\beta} X_{i}

In a logarithmic regression, the same logic applies, but the interpretation of the coefficient is somewhat different.

Interpreting B: Linear-log Model

In a linear-log model, like the one shown below, the regression coefficient β\beta gives you the estimated change in Y associated with a one-unit increase in ln(X).

Yi=α+βln(Xi)+ϵiY_{i}=\alpha + \beta\ln{(X_{i})}+\epsilon_{i}

While it’s difficult to interpret a one-unit increase in a logged term, a benefit of using logged variables in a regression is that the coefficient can be interpreted in terms of percentage changes. In the linear-log case, we can say that 1a p% increase in X results in an estimated change in Y that equals:

β×ln(100+p100)\beta \times \ln(\dfrac{100+p}{100})

As an approximation, we can also say that a one-percent increase in X is associated with aβ100\frac{\beta}{100} increase in Y.

Interpreting B: Log-linear Model

In a log-linear model, you can interpret the regression coefficient as the estimated percentage change in Y associated with a one-unit increase in X.

In this case, the percentage change is measured on a scale from 0-1. For example, a β\beta of 0.12 tells you that Y is estimated to increase by 12% in response to a one-unit increase in X.

Interpreting B: Log-log Model

In a log-log model, we can interpret the regression coefficient as the percentage change in Y that results from a one percent increase in the independent variable.

Unlike the log-linear case, the percentage change in the log-log model is measured on a scale of 0-100. So if β\beta=3.5, for example, Y is estimated to increase by 3.5% in response to a 1% increase in X. You will sometimes hear this type of coefficient being called elasticity, since elasticity measures the percentage change in one variable in response to a percentage change in another.

3 Steps To Calculate Logarithmic Regression

Below are steps you can follow to calculate a linear-log model.

Step 1. Enter your data

Suppose you have data on income—measured in thousands of dollars per year—and life expectancy—measured in years. Start by entering or uploading your data into a statistical program like R, Stata, Excel, or Desmos. For this example, we would likely use income to predict life expectancy, so your x-values will be income and your y-values will be life expectancies.

Step 2. Check a scatterplot

Next, plot your data on a scatterplot and check to see whether it’s appropriate to use linear-log model. Remember, logarithmic regression is used in cases where the relationship between X and Y matches the pattern of decelerating growth or decelerating decay.

Step 3. Fit a logarithmic function to your data

Finally, use your software to fit a linear-log function of the form Yi=a+βlnXi Y_i=a+ \beta lnX_i to your data.

Logarithmic Regression Solved Example

Here is a solved example of how to build the same linear-log regression we ‌discussed using Desmos. To do this, we are using a hypothetical dataset on income and life expectancy.

Step 1. The Data

We start by entering or uploading our data into Desmos as a table with x1x_1 representing annual income measured in thousands of dollars and y1y_1representing life expectancy in years.

Data table in Desmos

Step 2. The Scatterplot

Next, we click on the grey circular icon next to y1y_1 in the data table to plot the data points on a scatter plot. We check to see that data is nonlinear and matches the pattern of decelerating growth or decay. In this case, we see that the data seems to match an increasing logarithmic function. Life expectancy increases with age, but it does at a decelerating rate.

Data points on a scatter plot

Step 3. The Regression Results

Finally, we fit a linear-log function to the data by entering the following equation into Demos’ command line: y1b+mln(x1)y_{1}\sim b+m\ln(x_{1}). This will fit a curved line to the data and will show you your regression results.

We fit a linear-log function to the data by entering the equation into Demos’ command line

Desmos uses different notation for regressions than what we have used so far. In the Desmos equation, bb represents the intercept and mm represents the coefficient on ln(x1)ln(x_1).

The results show that the regression coefficient mm=8.31395.

Based on what you learned earlier about interpreting coefficients, we can say the following: a one percent increase in income (x1)(x_1) is associated with a m100\frac{m}{100} or 8.31395100\frac{8.31395}{100} increase in life expectancy (y1)(y_1). Or, as income increases by 1%, our model estimates life expectancy will increase by 0.0831 years.

model estimates life expectancy will increase by 0.0831 years

Explore Outlier's Award-Winning For-Credit Courses

Outlier (from the co-founder of MasterClass) has brought together some of the world's best instructors, game designers, and filmmakers to create the future of online college.

Check out these related courses:

Intro to Statistics

Intro to Statistics

How data describes our world.

Explore course
Intro to Microeconomics

Intro to Microeconomics

Why small choices have big impact.

Explore course
Intro to Macroeconomics

Intro to Macroeconomics

How money moves our world.

Explore course
Intro to Psychology

Intro to Psychology

The science of the mind.

Explore course

Share