Skip to content

Learn

AI-Assisted Evidence Checks

Log transforms: preserve zeros, negatives and the target

Taking logarithms changes the research target as well as the display scale. Zeros and negative values cannot simply disappear without changing the population being summarized. Before asking AI to fit or compare log-transformed data, specify the valid domain, units and interpretation of the transformed result.

The NumPy logarithm reference documents natural logarithms, including behavior for zero and invalid real inputs. Software output such as negative infinity or not-a-number is a computational result, not permission to silently delete the affected economic observations.

Record the transformation contract

Keep the raw value x, unit, transformed value, domain status and any offset. For real-valued ln(x), require x > 0. A zero outcome can be economically meaningful, while a negative financial measure may indicate a loss rather than a data error. Preserve those interpretations before selecting a method.

If the task only concerns positive observations, state that restricted population explicitly and show how many rows were excluded. If the original target includes all firms or all periods, a positive-only log summary answers a different question. Do not label it an all-company average after removing loss-making firms.

Specify the logarithm base. Natural logs and base-ten logs differ by a constant factor, which changes coefficient scale. Record any preprocessing order as well: deflation, currency conversion, aggregation and log transformation may not commute.

Hypothetical arithmetic and geometric summaries

Assume a fictional positive sample has values 1 and 9 in the same unit. The arithmetic mean is 5. The average natural log is (ln 1 + ln 9)/2 = ln 3, and exponentiating it returns 3, the geometric mean.

SummaryHypothetical resultTarget
Average raw value5Arithmetic mean
Average log valueApproximately 1.098612Mean on log scale
Exponential of mean log3Geometric mean

The difference between 5 and 3 is not a rounding error. Exponentiating an average log does not generally recover an average original value. Likewise, a model prediction on the log scale needs an explicit retransformation strategy if the desired target is an arithmetic mean. Do not automatically add a variance correction unless its distributional assumptions fit.

Now add a zero-valued observation. Plain logs no longer define a finite real summary for the full sample. Dropping zero changes the population; replacing zero with a small positive number changes the data. Neither should happen silently.

Examine offsets and units

An offset transformation ln(x + c) is defined only where x + c > 0. Record c in the same physical unit as x. Adding one dollar before converting units is not equivalent to adding one thousand dollars after expressing x in thousands.

For a hypothetical value of 100 dollars, ln(100 + 1) is about 4.615121. Expressing the value as 0.1 thousand dollars and then adding one gives ln(1.1), about 0.095310. These are different transformations, not merely different labels on the same result.

The numerical routine log1p can help evaluate ln(1 + x), but does not solve the conceptual choice of offset or the treatment of values at or below minus one. Alternative transformations also need interpretation; their ability to accept negative inputs is not evidence that they answer the original economic question.

Release an interpretable result

Show the original distribution, excluded-status counts, transformation and target statistic. Test a small dataset containing positive, zero and negative values before running a large panel. Distinguish domain failures from missing source values so an extraction error cannot be disguised as a mathematical exclusion.

Keep transformed estimates and original-unit summaries separately labeled. Recheck after unit changes, new negative observations, a changed offset or a different requested target. A smoother chart is not enough to justify a transformation that removes the cases central to the research question.

For two positive values, exponentiating the log difference recovers their ratio exactly. Calling the log difference itself a percentage change is only an approximation, and large changes can make that shortcut materially misleading.

FAQ

Does exponentiating the mean log give the ordinary mean?

No. It gives the geometric mean for positive equally weighted data. Arithmetic-mean retransformation requires additional treatment.

Does adding one make logs universally safe?

No. Domain restrictions remain, the offset depends on units, and the transformed target needs its own explanation.