Why Log a Positive Predictor?
A positive predictor can span several orders of magnitude: one observation may be 2 units while another is 2,000. On the original scale, the larger values can dominate a graph or a model’s numerical calculations. A logarithm compresses the scale, so equal multiplicative changes in the original predictor become equal additive changes on the transformed scale.
That compression can make a strongly right-skewed predictor easier to inspect and can reveal a more nearly straight relationship with an outcome. It does not guarantee either result. The transformed data still need to be examined in context, and a log should not be used merely because a variable has a long right tail.
log(x) computes the natural logarithm and log10(x) computes the base-10 logarithm.
A value between 0 and 1 has a negative logarithm, a value of 1 has logarithm 0, and a value greater than 1 has a positive logarithm. These signs depend on the units: a quantity of 0.5 dollars is less than 1 dollar, but the same quantity is 50 cents, which is greater than 1 cent. A negative logged value is therefore not evidence of invalid data; the original predictor must be positive.
What the Log Changes
The logarithm preserves the ordering of positive values: if \(0<a<b\), then \(\ln(a)<\ln(b)\), and the same is true for \(\log_{10}\). It changes the distances between observations. In particular, it treats ratios consistently: moving from 2 to 4 and moving from 20 to 40 are equal multiplicative changes, even though their raw differences are 2 and 20.
This identity follows from the logarithm rule \(\ln(b/a)=\ln(b)-\ln(a)\). It explains why equal ratios produce equal differences after logging. Another way to see the compression is to differentiate: the rate at which \(\ln(x)\) changes with \(x\) is \(1/x\). For the same small absolute increase in \(x\), the change in its logarithm is smaller when \(x\) is already large.
A log transformation does not make the predictor normally distributed by definition, remove influential observations, or guarantee a suitable model. It changes the predictor scale. Whether that scale is useful depends on the predictor’s distribution, the plotted relationship with the outcome, and the model’s purpose.
Comparing Natural and Base-10 Logs
Natural and base-10 logs contain the same ordering and ratio information. They differ by a constant multiplier:
Consequently, either base gives the same general shape when plotted against the same observations; one set of logged values is just a constant multiple of the other. If a regression includes an intercept and uses one logged predictor, changing the base changes the coefficient’s numerical scale but can leave fitted values unchanged after refitting. For example, because \(\ln(x)=\ln(10)\log_{10}(x)\), a term \(\beta_1\ln(x)\) can be written as \(\beta_1\ln(10)\log_{10}(x)\). This equivalence is not a reason to switch bases halfway through an analysis: use one definition consistently in model fitting and prediction.
Worked Example: Compressing a Wide-Ranging Predictor
A hypothetical analyst records four positive transaction amounts, in dollars: 1, 10, 100, and 1,000. Compare their raw and base-10-log scales. Then determine whether the log scale makes the successive multiplicative steps equally spaced.
Method. Compute each base-10 logarithm, then compare the raw and transformed ranges and successive gaps.
The transformed values are:
On the raw scale, the range is \(1000-1=999\). The three successive gaps are \(10-1=9\), \(100-10=90\), and \(1000-100=900\). On the transformed scale, the range is \(3-0=3\), and every successive gap is \(1\).
The raw arithmetic mean is \((1+10+100+1000)/4=1111/4=277.75\). The mean of the logged values is \((0+1+2+3)/4=6/4=1.5\). These means are on different scales and should not be compared as if they measured the same quantity.
Check. Each transaction amount is 10 times the preceding amount, and each corresponding logged value increases by exactly 1. The log compresses the wide raw range and makes these equal ratios equally spaced. A common mistake would be to claim the gaps are equal on the original scale; they are 9, 90, and 900, not equal.
Check Whether the Outcome Relationship Improves
A useful predictor transformation can also make the relationship between a predictor and an outcome more nearly linear. Compare the outcome against both the raw predictor and its log, using plots or model diagnostics appropriate to the analysis. A curved raw-scale pattern that becomes roughly straight on a logged scale may support using the logged predictor. The transformation should not be chosen solely because the predictor histogram looks more symmetric: the relationship with the outcome matters too.
The following example uses a simple regression to show the arithmetic. The purpose is to compare predictor scales, not to assert that a log transformation is appropriate for every outcome or model. Model assumptions concerning the outcome and errors are still relevant and are not established just because a predictor has been logged.
Worked Example: Comparing Raw and Logged Predictor Scales
In a hypothetical study of a service index \(y\), an analyst observes a positive resource measure \(x\) and the following values:
| \(x\) | \(y\) | \(z=\log_{10}(x)\) |
|---|---|---|
| 1 | 5 | 0 |
| 10 | 8 | 1 |
| 100 | 11 | 2 |
| 1,000 | 14 | 3 |
Fit a least-squares line for \(y\) using \(z=\log_{10}(x)\), and compare the pattern with the raw-scale increments.
Step 1: Transform the predictor. The base-10 logs are \(0,1,2,3\), as shown in the table.
Step 2: Compute the means. The transformed-predictor mean is \(\bar z=(0+1+2+3)/4=1.5\). The outcome mean is \(\bar y=(5+8+11+14)/4=38/4=9.5\).
Step 3: Compute the least-squares slope. The centered products \((z_i-\bar z)(y_i-\bar y)\) are \(6.75, 0.75, 0.75,\) and \(6.75\), which sum to \(15\). The squared centered predictor values are \(2.25, 0.25, 0.25,\) and \(2.25\), which sum to \(5\). Thus the slope is \(15/5=3\).
Step 4: Compute the intercept and fitted values. The intercept is \(\bar y-3\bar z=9.5-4.5=5\). The fitted equation is \(\hat y=5+3z\). For \(z=0,1,2,3\), the fitted values are \(5,8,11,14\), respectively, so every residual is 0.
On the raw scale, each increase in \(y\) is 3, but the corresponding increases in \(x\) are 9, 90, and 900. The outcome increments per raw unit are therefore \(3/9=0.3333\), \(3/90=0.0333\), and \(3/900=0.0033\), rounded to four decimal places. The logged predictor expresses the four points as an exact straight-line relationship in this constructed example.
Check. The fitted values reproduce all four observed outcomes, so the residuals sum to 0 and the calculation is consistent. The common mistake is to assume a straight-line pattern on the raw scale just because the outcomes increase by equal amounts; the raw predictor gaps are not equal. In a real analysis, plots and validation—not this constructed pattern alone—would inform the choice.
Domain, Units, and Unsuitable Cases
A direct logarithm is defined only for a strictly positive input. If a predictor contains zero or negative observations, applying \(\ln(x)\) or \(\log_{10}(x)\) to the full column is invalid. Do not silently remove those observations, replace them with small positive values, or change the formula without a defensible reason. The later topic on log one plus addresses a different transformation and its own conditions; it is not the same as taking the direct logarithm.
A log may also be a poor choice when it does not improve the relationship with the outcome, when a linear pattern on the raw scale is already adequate, or when the resulting model is hard to explain in the application. Compression can make extreme values look closer together, but it does not mean that the original observations should be discarded. Inspect the original values and retain context when communicating conclusions.
Changing units of a positive predictor adds a constant to its logarithm. If \(c>0\) is a unit-conversion factor, then \(\ln(cx)=\ln(c)+\ln(x)\). In a model with an intercept and the same other predictors, this constant shift can be absorbed by the intercept; without an intercept, that equivalence need not hold. Always apply the same units and transformation to new data that were used when fitting the model.
Worked Example: Checking the Log Domain and a Unit Conversion
A hypothetical processing-time predictor is recorded in days as \(0,\ 0.5,\ 2,\ 8\). The analyst considers its natural logarithm. Identify which observations can be transformed directly, compute those transformed values to four decimal places, and determine the effect of recording time in hours instead.
Step 1: Check the domain. The value 0 is not strictly positive, so \(\ln(0)\) is undefined. The values \(0.5,\ 2,\) and \(8\) are positive and can be transformed.
Step 2: Compute the valid natural logarithms.
The values are rounded to four decimal places. The zero observation cannot be included using this direct transformation.
Step 3: Convert the positive times to hours. The positive values become \(12,\ 48,\) and \(192\) hours. Since one day is 24 hours, the logged values each increase by \(\ln(24)=3.1781\):
For example, \(\ln(12)=\ln(0.5\times24)=\ln(0.5)+\ln(24)\), which is approximately \(-0.6931+3.1781=2.4849\). The same addition applies to the other two observations.
Check. Each logged value in hours is 3.1781 higher than the corresponding value in days, to four decimal places. The ordering and gaps among the positive logged values are unchanged. The common mistake is to treat changing units as a way to make the zero valid; multiplying zero by 24 still gives zero, and its direct logarithm remains undefined.
Practical Selection and Common Traps
Before fitting a model with a logged predictor, work through a short set of checks. These checks help distinguish a useful change of scale from an automatic transformation.
Confirm that every value to be transformed is strictly positive. Investigate zeros, negative values, and data-entry problems rather than masking them.
Use the natural logarithm or base-10 logarithm consistently. Record the chosen units and apply the same transformation when scoring or evaluating new cases.
Inspect the predictor before and after transformation, then examine its relationship with the outcome. Look for a meaningful improvement rather than assuming the log scale is better.
Assess the fitted model using its relevant assumptions and evaluation methods. A log transform changes the predictor; it does not by itself validate the model.
A frequent exam trap is confusing the two log bases. For example, \(\ln(100)\) is about 4.6052, whereas \(\log_{10}(100)=2\). Both transformations are valid for \(x=100\), but they do not produce the same numerical predictor values. Another trap is treating a negative log value as an invalid input: \(\ln(0.5)\) is defined and equals approximately \(-0.6931\); it is the original input, not the transformed result, that must be positive.
Check Your Understanding
Work each problem before checking its answer.
- A hypothetical predictor takes the values \(0.1,\ 1,\) and \(1{,}000\). Find the base-10 logarithm of each value and the range of the transformed values. (Answer: \(-1,\ 0,\ 3\); range \(4\).)
- For positive values \(a=5\) and \(b=40\), calculate \(\ln(b)-\ln(a)\) using the ratio identity, rounded to four decimal places. (Answer: \(\ln(8)=2.0794\).)
- A predictor changes from 2 to 8. Find the change in its natural logarithm, rounded to four decimal places, and state the ratio represented by that change. (Answer: \(\ln(8)-\ln(2)=\ln(4)=1.3863\); the ratio is \(8/2=4\).)
- A data column contains \(-3,\ 0,\ 0.25,\) and \(4\). Which values can be directly transformed with a logarithm, and why can changing measurement units not make the other two valid? (Answer: \(0.25\) and \(4\) can; multiplying by a positive unit-conversion factor leaves \(-3\) negative and 0 equal to 0.)
- A model contains the predictor term \(2\ln(x)\). Write the equivalent term using \(\log_{10}(x)\), rounded to four decimal places for its coefficient. (Answer: \(2\ln(x)=2\ln(10)\log_{10}(x)\), so the term is approximately \(4.6052\log_{10}(x)\).)