liveBook · Manning

Data transformation

As explained in Effective Data Analysis

A data transformation is a mathematical or computational modification of data values intended to change their representation, scale, distribution, or modeled relationship.

Data transformation modifies a variable’s representation to better satisfy statistical assumptions or represent a relationship for analysis. In regression, transformation is considered after inspecting distributions, correlations, and residual behavior. section 9.2.1 section 4.3.4

Use transformation as part of an iterative analysis workflow:

  • Inspect distributions and relationships with plots, correlations, and residual diagnostics before changing variables. section 9.2.1
  • Transform a predictor when its relationship with the outcome may be curvilinear; squared and square-root wind-speed variables provide alternatives for comparison. section 9.2.1
  • Transform an outcome when the original scale produces problematic residuals; taking the square root of rat sightings improved the modeled results in the illustrated iteration. section 9.2.2
  • Separate transformation from data cleaning: remove or replace missing values appropriately and investigate erroneous outliers before judging model changes. section 9.2.2

Weather and rat-sighting regression

A model relating weather to daily rat sightings showed extreme low-temperature outliers and a potentially nonlinear pattern. After removing an erroneous record, fitting the model with the square root of rat sightings produced a different model scale, explained up to 60% of the variance in that transformed outcome, and had lower AIC and BIC. section 9.2.2

X = rats_weather[["high_temp", "wind_speed", "weekday"]]
y = np.sqrt(rats_weather["rat_sightings"])    #1
X = sm.add_constant(X)

model = sm.OLS(y, X).fit()
print(model.summary())     #2

The listing shows a square-root transformation applied to the regression outcome before fitting the model. section 9.2.2

How Effective Data Analysis covers it

How deep it goes
Explains exploratory diagnosis, predictor and outcome transformations, and iterative model evaluation, but does not catalog transformation families.
Examples
Demonstrates squared and square-root wind speed, square-root rat sightings, weather outlier removal, and Boston–New York weather testing.
What it assumes
Assumes familiarity with distributions, correlations, regression, and inferential assumptions while reinforcing their practical evaluation.
What you can do after
Diagnose model problems and apply transformations while reporting what the transformed results can and cannot mean to stakeholders.
How it connects
Connects transformations with statistical assumptions, linear regression, residuals, outliers, distributions, correlations, and power analysis.

Also explained in

Compare how 20 books explain data transformation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.