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



















