Transformation Lab

Regression Foundations Data Preparation

Read your residuals, find out whether a transformation is actually warranted, compare the candidates honestly on the original scale of your outcome, and walk away with the exact formula for Excel, Sheets, Python, R, SPSS or Stata.

πŸ‘¨β€πŸ« Professor Mode: Guided Learning Experience

New to transformations? Enable Professor Mode for step-by-step guidance through diagnosing a model, choosing a transformation for a reason, and interpreting what your coefficients mean afterwards!

WHY WOULD YOU CHANGE YOUR DATA?

The first time someone suggests re-expressing a variable before analysing it, the reaction is usually suspicion. Isn't changing your numbers the definition of cooking the books?

It's a fair worry, and the answer is worth getting straight before you touch anything. A transformation does not change your data. It changes the scale you measure it on β€” and you already accept that move everywhere else.

You already do this

Earthquakes are reported on the Richter scale, sound in decibels, acidity in pH, stock moves in percentages. Every one of those is a logarithm. Nobody thinks the Richter scale falsifies earthquakes β€” it's just the scale on which earthquake sizes behave sensibly.

Nothing is discarded

Every transformation here is reversible. The order of your customers is preserved, no row is dropped, and a prediction can always be converted back into dollars. If it could not be undone, it would not be on this page.

The straight line is the assumption

Fitting a line to a curved relationship is not the neutral, assumption-free choice. It is a strong claim that every extra dollar of spend does the same work as the last. Re-expressing the scale is often how you stop asserting something false.

So when is it cooking the books?

There is a real line here, and it has nothing to do with whether you transformed. It is about when you decided to and what you report.

  • Fine: the residuals showed a problem, you fixed the scale, and you reported the model you ended up with β€” including the fact that you changed it.
  • Not fine: you tried eleven transformations, kept the one with the best p-value, and reported it as though it were the only thing you tried.

The second is p-hacking, explained below. This tool is built to make the first easy and the second visible.

Two kinds of change, and only one of them affects fit

Every transformation on this page does one of two quite different jobs. Telling them apart is the single most useful thing on this screen, because most people believe both kinds improve a model, and only one of them can.

1. Shape-changing

\( \ln(x),\ \sqrt{x},\ x^{2},\ 1/x \)

Changes model fit. These stretch some parts of the scale and squash others, so the relationship you are fitting genuinely changes. A gap of $10 near the bottom stops counting the same as a gap of $10 near the top.

Use when the residuals say a straight line is the wrong shape, or that the error grows with the size of the prediction.

2. Scale-changing

\( \alpha x + \beta \)

Cannot change model fit. Centering, z-scores, 0–100 rescaling, index = 100, switching dollars to thousands. Gaps stay in exactly the same proportion to each other β€” the ruler is relabelled, not bent.

Use for interpretation and presentation. RΒ² and the size of every slope's t statistic come back identical, and Step 4 proves it on your own data.

Either way, the model you fit is: $$ f(Y_i) = \beta_0 + \beta_1\, g(X_i) + \varepsilon_i $$ where \(f\) and \(g\) are whatever you chose to do to the outcome and the predictor. Choose nothing, and both are simply "leave it alone".

Two very different reasons to reshape

When you reach for a shape-changing transformation, it is worth being honest with yourself about why. There are two answers, they carry very different weight, and the difference is what separates analysis from fishing.

🎯 Because you expected it

Theory-driven Β· strongest ground

You had a reason before you looked at the residuals. Marketing is full of these, and they are not exotic:

  • Diminishing returns β€” the millionth impression cannot do what the first did. That is a log of the predictor, and you could have said so before seeing the data.
  • Proportional effects β€” a 10% lift means the same thing to a small account and a large one. That is a log of the outcome.
  • Elasticity β€” price work is conventionally done in percentage terms, which is a log on both sides.
  • Saturation and wear-out β€” a response that flattens, or turns over entirely, at high exposure.

You can defend this in a meeting, and it will usually hold up on next quarter's data, because it was never about this sample.

πŸ” Because the residuals told you

Diagnostic-driven Β· legitimate, with conditions

You had no prior expectation, you fitted the model, and the diagnostics showed something was wrong β€” a fan, an arc, a badly skewed outcome. Fixing it is the right response, not a compromise.

Two conditions keep this honest:

  • Let the symptom pick the remedy. Decide from the residual plot what kind of problem you have, then apply the transformation that addresses it. Do not run every option and take the winner.
  • Say what you did. "We logged revenue because the residuals fanned out" is a complete, respectable sentence. Silence about it is the problem, not the transformation.

Ask yourself afterwards: can I now tell a story about why this shape makes sense? If yes, you have upgraded to the column on the left. If no, treat the result as provisional.

⚠️ The third reason, and the one to avoid: because it improved the number

If you try every transformation and keep whichever gave the best RΒ² or the smallest p-value, you are doing something with a name: p-hacking, also called data dredging or specification search.

Why it actually breaks things, rather than just being frowned upon:

  • A p-value of 0.05 means "this would happen 1 time in 20 by chance alone". Try twenty options and you should expect one to clear that bar even when nothing whatsoever is going on. The test has not misfired β€” you simply gave it twenty chances and reported the one that succeeded.
  • The reported p-value assumes you ran one test. After a search it is no longer the right number, and there is no honest way to quote it as if it were.
  • What you have fitted is partly the noise in this particular sample. Noise does not repeat, so the effect shrinks or vanishes on new data β€” which is exactly when a campaign built on it is already running.

Ten of these fitted models never happened, as far as the reader of your report is concerned. That's the deception β€” not the transformation itself, but the nine or ten silent attempts behind it.

What this tool does about it. Step 2 shows you every candidate, so you can see how small the differences usually are. Model mode scores each candidate on data it never saw and tells you how many models it fitted. When a search does find something, change the seed and re-run: a real effect survives, a hacked one does not.

Why a transformed RΒ² can't be compared with an untransformed one

If you fit \(\ln(Y)\) instead of \(Y\), you have changed the outcome. The total amount of variation available to explain is different, so RΒ² is answering a different question and the two numbers are not on the same footing. Ranking candidates that way would simply reward whichever transformation compressed the outcome most.

Everything on this page is therefore scored the honest way: fit on the transformed scale, predict, convert the predictions back into the original units of your outcome, and only then measure the error.

What your coefficients mean afterwards
Model form A one-unit rise in X…
\(Y \sim X\)changes Y by \(b\) units
\(\ln Y \sim X\)changes Y by about \(100 \times b\) percent
\(Y \sim \ln X\)a 1% rise in X changes Y by about \(b/100\) units
\(\ln Y \sim \ln X\)a 1% rise in X changes Y by \(b\) percent β€” \(b\) is an elasticity

DATA SOURCE

πŸ“š

Use a Case Study

Each scenario is built around a different diagnosis, so you can see what the residuals look like when the outcome is the problem, when the shape is the problem, and when nothing is the problem at all.

πŸ“‚

Upload Your Data

Upload a CSV with headers and at least two numeric columns β€” one outcome and one predictor.

Drag & drop a data file (.csv, .tsv, .txt, .xls, .xlsx)

Headers required. Numeric outcome and predictor.

No file uploaded.

WHEN TRANSFORMATION IS NOT ENOUGH

Every option in this lab bends a continuous scale and keeps it continuous. Sometimes that is not sufficient β€” the relationship rises, falls and rises again, or the variable has a pile of zeros and a long tail that no single curve fits. Three alternatives come up often enough in applied marketing work to be worth naming. None of them is offered above, deliberately: this lab is about functional form, and mixing these in would blur that.

Ordered categories and dummy variables

Cut the continuous predictor into bands β€” Low / Medium / High, or substantively meaningful ranges such as under $50, $50–$200, over $200 β€” and enter them as indicator variables. The model then estimates a separate effect for each band and imposes no shape at all, which is why it can follow a relationship that wanders.

Reasonable when: the cut points already exist in the business (pricing tiers, loyalty levels, a media flighting plan), or the relationship genuinely steps rather than flows.

What it costs you: this is the expensive option, and it is routinely chosen for the wrong reason β€” because categories are easier to present.

  • Information is discarded. Everyone inside a band is treated as identical, so a customer at $51 and one at $199 become the same case.
  • The cut points are arbitrary unless the business supplied them, and moving a boundary a little can move your conclusion a lot.
  • Statistical efficiency drops. You spend several coefficients where one would have done, and you need more data for the same precision.
  • Estimates get less precise, so real effects are harder to detect β€” and a boundary chosen because it produced a significant result is p-hacking wearing different clothes.

Splines and piecewise fits

Keep the variable continuous, but let the curve change shape at a few points along the way. This buys most of the flexibility of categories without throwing away the distinctions inside each band, which is why it is usually the better answer when "Low / Medium / High" is tempting.

Reasonable when: the relationship clearly changes direction or slope partway along, and you have enough rows to support the extra flexibility.

What it costs you: no single coefficient to quote, and a real risk of fitting the wiggles in this particular sample.

A different model, not a different scale

Sometimes the scale is fine and the model is wrong. Counts with many zeros, a proportion bounded at 0 and 1, or a wait until an event each have models built for them β€” Poisson and negative binomial, beta or logistic, survival models. Logging the outcome to force it into linear regression is a workaround for a problem those models simply do not have.

Reasonable when: your outcome is a count, a proportion, a binary event or a duration.

What it costs you: mostly unfamiliarity β€” and note that a count model handles the zeros that block the log family here.

REFERENCES & METHODOLOGICAL BACKGROUND

Nothing in this lab is new. Each piece of it traces to a specific paper, and these are the ones worth knowing by name.

The transformations themselves

  • Box, G. E. P., & Cox, D. R. (1964). An analysis of transformations. Journal of the Royal Statistical Society: Series B, 26(2), 211–243. https://doi.org/10.1111/j.2517-6161.1964.tb00553.x The paper behind the Ξ» on this page. It replaced "try a log and see" with estimating the right power from the data.
  • Tukey, J. W. (1977). Exploratory Data Analysis. Addison-Wesley. The origin of the ladder of powers, and of the habit of looking at the residuals before trusting the model.
  • Yeo, I.-K., & Johnson, R. A. (2000). A new family of power transformations to improve normality or symmetry. Biometrika, 87(4), 954–959. https://doi.org/10.1093/biomet/87.4.954 Extends Box-Cox to variables containing zero and negative values, which is why it never appears as unavailable above.
  • Sakia, R. M. (1992). The Box-Cox transformation technique: a review. The Statistician, 41(2), 169–178. https://doi.org/10.2307/2348250 The readable overview to start with if the 1964 paper is heavy going.

Deciding whether you need one

  • Breusch, T. S., & Pagan, A. R. (1979). A simple test for heteroscedasticity and random coefficient variation. Econometrica, 47(5), 1287–1294. https://doi.org/10.2307/1911963 The fanning-residuals test reported in Step 1.
  • Ramsey, J. B. (1969). Tests for specification errors in classical linear least-squares regression analysis. Journal of the Royal Statistical Society: Series B, 31(2), 350–371. https://doi.org/10.1111/j.2517-6161.1969.tb00796.x RESET, the curvature test in Step 1. It asks whether the wrong functional form was fitted.

Living with a transformed model

  • Duan, N. (1983). Smearing estimate: a nonparametric retransformation method. Journal of the American Statistical Association, 78(383), 605–610. https://doi.org/10.1080/01621459.1983.10478017 Converting a prediction back into dollars is biased if you simply exponentiate. This is the correction applied in Step 3.
  • Gelman, A. (2008). Scaling regression inputs by dividing by two standard deviations. Statistics in Medicine, 27(15), 2865–2873. https://doi.org/10.1002/sim.3107 On the second family β€” why rescaling is an interpretation decision rather than a modelling one.

On categorising instead

  • Royston, P., Altman, D. G., & Sauerbrei, W. (2006). Dichotomizing continuous predictors in multiple regression: a bad idea. Statistics in Medicine, 25(1), 127–141. https://doi.org/10.1002/sim.2331 The source of the tradeoffs listed in the previous section, argued in detail.
  • MacCallum, R. C., Zhang, S., Preacher, K. J., & Rucker, D. D. (2002). On the practice of dichotomization of quantitative variables. Psychological Methods, 7(1), 19–40. https://doi.org/10.1037/1082-989X.7.1.19 Quantifies what a median split actually costs you in power.