Why Use Log1p?
A predictor such as the number of visits, messages, or recorded events may be nonnegative and may equal zero for some observations. The ordinary logarithm \(\ln(x)\) is undefined at \(x=0\), so a regression using \(\ln(x)\) cannot directly include those observations. The transformation called log1p, defined as \(\ln(1+x)\), is defined at zero and increases more slowly as \(x\) grows.
Using log1p does not mean that a zero is missing, or that it should be replaced by an arbitrary small positive number. Zero is a valid predictor value, and the transformed value at zero is exactly zero. The transformation also changes how the regression mean responds to increases in the original predictor: its slope is greatest near zero and decreases as \(x\) increases.
Behavior Near Zero and at Large Values
Near zero, log1p is close to the identity transformation \(x\mapsto x\): small increases in \(x\) produce nearly the same-sized increases in \(\ln(1+x)\). As \(x\) becomes large, log1p behaves increasingly like \(\ln(x)\), because the added 1 becomes small relative to \(x\). These approximations describe the transformation; they do not imply that the response has a linear or logarithmic relationship with \(x\) in every application.
The following justification makes both comparisons precise. Since \(g'(x)=1/(1+x)\) and \(g(0)=0\), the fundamental theorem of calculus gives \(g(x)=\int_0^x 1/(1+t)\,dt\). Rewriting the integrand as \(1-t/(1+t)\) gives:
For \(x\geq 0\), the integral is nonnegative and no greater than \(\int_0^x t\,dt=x^2/2\), because \(0\leq t/(1+t)\leq t\). Thus \(0\leq x-\ln(1+x)\leq x^2/2\); the difference from \(x\) is small when \(x\) is small.
For \(x>0\), a second identity describes the large-value behavior:
The final term is positive and at most \(1/x\), using \(\ln(1+u)\leq u\) for \(u\geq 0\). Consequently, the difference between \(\ln(1+x)\) and \(\ln(x)\) becomes small as \(x\) grows. At zero, however, log1p remains defined while \(\ln(x)\) does not.
Worked Example: Checking the Transformation at Small and Large Values
Suppose \(x\) is a nonnegative event count. Compare log1p with \(x\) near zero, and with \(\ln(x)\) at a large value. All values below are hypothetical.
Near zero. At \(x=0.01\), the transformed value is \(\ln(1.01)\approx 0.009950\). Its difference from \(x\) is \(0.01-0.009950=0.000050\), so the two values are close. The derivative at this point is \(g'(0.01)=1/1.01\approx 0.9901\), also close to 1.
At a large value. At \(x=100\), \(\ln(1+x)=\ln(101)\approx 4.6151\), while \(\ln(x)=\ln(100)\approx 4.6052\). The difference is \(\ln(1.01)\approx 0.009950\), and the bound above gives a difference no greater than \(1/100=0.01\). Thus the log1p value is close to the log value here, but not identical.
These calculations describe the predictor transformation alone. Whether it gives a useful relationship with an outcome must be considered in the regression context.
Regression With a Log1p Predictor
A simple regression mean function using log1p can be written as:
Here \(Y_i\) is the response for observation \(i\), \(x_i\) is its nonnegative predictor value, \(\beta_0\) is the intercept, \(\beta_1\) is the coefficient of the transformed predictor, and \(\varepsilon_i\) is the error. For interpreting the mean function, the key assumption is that the conditional mean of the error is zero: \(E(\varepsilon_i\mid x_i)=0\). This means that the model’s conditional mean response is \(\beta_0+\beta_1\ln(1+x_i)\).
The usual regression framework also treats observations’ errors as independent with a common variance when that framework is appropriate. Normal errors are an additional assumption when using standard small-sample \(t\)-based inference. Those assumptions concern the errors, not the fact that the predictor has been transformed. A fitted coefficient alone does not establish that the model assumptions hold.
The intercept \(\beta_0\) is the model’s mean response at \(x=0\), since \(\ln(1+0)=0\). The coefficient \(\beta_1\) describes the change in mean response for a one-unit increase in the transformed predictor, not for a one-unit increase in \(x\). Its units are response units per one unit of \(\ln(1+x)\). For a change from \(x=a\) to \(x=b\), the model-implied change is:
The marginal slope with respect to the original predictor follows from differentiating the conditional mean function:
Thus, if \(\beta_1\) is positive, the model predicts an increasing mean response, but the increase per additional unit of \(x\) is greatest at zero and diminishes as \(x\) grows. If \(\beta_1\) is negative, the predicted mean decreases, with the magnitude of the local slope likewise diminishing as \(x\) grows. These are descriptions of an association in the model; they do not by themselves establish a causal effect.
Worked Example: Interpreting a Fitted Log1p Model
Suppose a hypothetical fitted model predicts weekly service time \(Y\), in minutes, from the number of requests \(x\):
Assume the observed request counts are nonnegative and that the conditional-mean model is being used for these predictions. The formula can include an observation with zero requests because \(\ln(1+0)=0\). At \(x=0\), the predicted mean is \(12+3.2(0)=12\) minutes.
For an increase from zero to one request, substitute both predictor values:
The predicted mean at one request is therefore about \(12+2.218=14.218\) minutes. This change is not \(3.2\) minutes: a one-request increase does not correspond to a one-unit increase in \(\ln(1+x)\).
Now compare nine requests with ten. The predicted change is:
The local slope at \(x=9\) is \(3.2/(1+9)=0.32\) minutes per additional request, close to the finite change of \(0.3050\) minutes for the increase from nine to ten. Both changes are smaller than the increase from zero to one, as the model’s decreasing slope implies. These are model-based mean predictions, not guaranteed outcomes for individual weeks.
Why Its Slope Is Not a Log-x Slope
A regression using \(\ln(1+x)\) is not the same as one using \(\ln(x)\). They have different domains: log1p includes zero, while log \(x\) requires \(x>0\). Even where both transformations are defined, their slopes differ. For a conditional mean \(\beta_0+\beta_1\ln(1+x)\), the derivative with respect to \(x\) is \(\beta_1/(1+x)\). For \(\beta_0+\beta_1\ln(x)\), it is \(\beta_1/x\). In a log-x model, a proportional change in \(x\) has a constant effect on the model mean; that is not generally true for log1p.
The distinction is also visible in the response to doubling \(x\). Under a log-x model, doubling changes the predictor by \(\ln(2x)-\ln(x)=\ln(2)\), wherever \(x>0\). Under log1p, doubling changes it by \(\ln(1+2x)-\ln(1+x)=\ln((1+2x)/(1+x))\), which depends on the starting value of \(x\).
Worked Example: Comparing the Effect of Doubling
Consider two hypothetical models for the same response, each with coefficient \(\beta_1=2\) response units per transformed-predictor unit. Compare the model-implied changes when \(x\) doubles from one to two and from ten to twenty.
Log1p model, from one to two. The change is \(2[\ln(3)-\ln(2)]=2\ln(3/2)\approx 2(0.4055)=0.8109\) response units.
Log1p model, from ten to twenty. The change is \(2[\ln(21)-\ln(11)]=2\ln(21/11)\approx 2(0.6466)=1.293\) response units. Doubling does not have the same effect at these two starting values.
Log-x model, either doubling. The change is \(2[\ln(2x)-\ln(x)]=2\ln(2)\approx 1.386\) response units, whether \(x\) goes from one to two or from ten to twenty. This model cannot make a prediction at \(x=0\), because \(\ln(0)\) is undefined.
The coefficients in these illustrative models are equal, but their effects on the original predictor scale are not interchangeable. A coefficient from one transformation should not be interpreted using the slope rule for the other.
Practical Checks and a Common Mistake
Log1p is useful when a nonnegative predictor has zeros and a regression mean that bends as \(x\) increases is substantively and empirically reasonable. It does not guarantee a good fit, remove outliers, or make the errors satisfy regression assumptions. Examine the relationship and residual behavior in the usual way, and keep the predictor’s measurement unit explicit: the numerical values used to calculate \(\ln(1+x)\) determine the transformed predictor.
A common mistake is to say, “The coefficient is 3.2, so each additional request increases the mean response by 3.2 minutes.” That is incorrect because the model coefficient multiplies \(\ln(1+x)\), not \(x\). The correction is to calculate the transformed difference for a specified interval, \(\beta_1\ln((1+b)/(1+a))\), or use the marginal slope \(\beta_1/(1+x)\) at a particular value. The effect per additional request therefore depends on the starting count.
Another mistake is to call a log1p model a log-x model merely because their transformations become close for large \(x\). They are not identical, and their behavior at zero is fundamentally different. The model form and its interpretation should match the transformation actually used.
Check Your Understanding
Answer each question using the transformation and model interpretations developed above.
- What is the log1p-transformed value when \(x=0\), and why can a log-x model not use that same predictor value?
- For \(x=0.02\), explain why \(\ln(1+x)\) is close to \(x\), using the bound \(0\leq x-\ln(1+x)\leq x^2/2\).
- For a model mean \(\beta_0+5\ln(1+x)\), what is the model-implied mean change from \(x=2\) to \(x=5\)? Give the exact expression.
- In a log1p model with positive coefficient, how does the marginal slope with respect to \(x\) change as \(x\) increases? State the derivative.
- Why does a log-x model give the same model-implied change for any doubling of a positive \(x\), while a log1p model generally does not?