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!

OVERVIEW & WHAT THIS TOOL SOLVES

Fitting a straight line to skewed revenue or diminishing-returns ad spend makes the strongβ€”and often falseβ€”claim that your millionth impression does the exact same work as your first. Re-expressing a variable on a logarithmic, square-root, or standardized scale doesn't "cook the books"; it changes the ruler so curved, proportional, or skewed marketing relationships behave linearly without dropping a single customer. Transformation Lab diagnoses whether your residuals actually warrant a transformation, separates shape-changing transformations from scale-changing ones, and scores every candidate back on the original dollar scale.

🎯 Questions It Answers

  • Do our regression residuals show curvature or a widening funnel that warrants re-expressing the outcome or predictor?
  • Which transformations actually change model fit (shape-changing) vs. simply relabel the ruler for easier interpretation (scale-changing)?
  • Which candidate transformation predicts best on the original outcome scale without falling into the p-hacking trap?

πŸ“‚ What Data You Need

  • Case-Level CSV or Preset Scenario: Paired observations across customers, stores, or time periods.
  • 1 Continuous Outcome: Numeric dependent variable (positive values required for log/square-root forms).
  • 1 Continuous Predictor: Numeric marketing input or behavioral driver.

πŸ’‘ What You'll Discover

  • Residual Diagnosis First: Visual checks showing whether the untransformed straight line is already fine or systematically wrong.
  • Original-Scale Error Comparison: Honest back-transformed RMSE and holdout validation across log, root, power, and linear forms.
  • Copy-Ready Formulas & Plain-English Slopes: Exact elasticity or percentage-change interpretations plus Excel, R, Python, and Stata code.
πŸ” Key Nuances: Shape vs. Scale, Theory vs. Diagnostics & Avoiding P-Hacking

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 sizes behave sensibly.

1. Shape-changing (changes fit)

Logarithms, square roots, squares, and reciprocals stretch some parts of the scale and squash others. Use when residuals curve or fan out with prediction size.

2. Scale-changing (cannot change fit)

Centering, z-scores, 0–100 rescaling, or converting dollars to thousands relabels the ruler without bending it. R-squared and slope t-statistics stay identical.

🎯 Because you expected it (Theory-driven)

Diminishing returns on ad impressions (log of X), proportional percentage lifts across small and large accounts (log of Y), or price elasticity (log of both Y and X) are grounded in marketing theory before you ever look at the data.

πŸ” Because the residuals told you (Diagnostic-driven)

Let the residual symptom pick the remedyβ€”such as logging a right-skewed outcome when errors fan outβ€”and state transparently in your report what you changed and why.

⚠️ The third reason, and the one to avoid: because it improved the number (P-Hacking)

Trying twenty transformations and reporting only the one that cleared p < 0.05 fits the random noise in your sample rather than a repeatable marketing effect. In addition, you cannot compare the raw R-squared of ln(Y) directly against the R-squared of Y because they measure variance on different scalesβ€”this tool always converts predictions back into original outcome units before comparing error.

πŸ“ Under the Hood: Model Equations & Variable Definitions
1. Generalized Transformed Regression & Slope Interpretations
\[ f(Y_i) = \beta_0 + \beta_1\, g(X_i) + \varepsilon_i \] \[ \text{Lin-Log: } Y_i = \beta_0 + \beta_1 \ln(X_i) + \varepsilon_i, \qquad \text{Log-Lin: } \ln(Y_i) = \beta_0 + \beta_1 X_i + \varepsilon_i, \qquad \text{Log-Log: } \ln(Y_i) = \beta_0 + \beta_1 \ln(X_i) + \varepsilon_i \]
πŸ’¬ Read it in plain English: Applying transformation f to the outcome and/or g to the predictor lets a linear regression capture curves and proportional changes: in Log-Lin, a 1-unit rise in X changes Y by ~100Ξ²1%; in Lin-Log, a 1% rise in X changes Y by ~Ξ²1/100 units; and in Log-Log, a 1% rise in X changes Y by Ξ²1% (an elasticity).
Yi, Xi
Raw Outcome & Predictor YOUR DATA β“˜
Observed outcome (Yi) and predictor (Xi) in their original measurement units.
f(Yi), g(Xi)
Outcome & Predictor Transformation Functions YOUR DATA β“˜
Chosen reversible scale functions applied to the outcome (f) and predictor (g) before OLS estimation.
Ξ²0, Ξ²1
Transformed-Scale Intercept & Slope ESTIMATED β“˜
Baseline intercept (Ξ²0) and slope (Ξ²1) relating g(X) to f(Y) (representing unit change, semi-elasticity, or full elasticity).
Ξ΅i, fβˆ’1(Β·)
Transformed Residual & Back-Transformation OUTPUT β“˜
Residual error on the fitted scale (Ξ΅i) and inverse mapping (fβˆ’1, e.g., exp) used to score predictions in original units.

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.