Auditing a Dwell-Time Linear Regression Pipeline
Statistics & ExperimentsModel answerLast updated
Review a colleague's OLS workflow for predicting session dwell time from four predictors, and explain what is wrong, what you would ask, and how you would rebuild it.
A colleague has handed you a modeling workflow for review. Your job is to critique it and say what you would do differently.
Setting
Visitors reach a website by clicking a result in a search engine. The outcome Y is the number of seconds a visitor stays on the site during that session (session dwell time). There are four candidate predictors, X1 to X4. You are not told what they are, and they may be a mix of numeric and categorical features. The sample size is also not given.
The colleague's workflow
- Y looks roughly bell-shaped in a histogram, so they decided ordinary least squares (OLS) was appropriate.
- They fit every subset of the four predictors, allowing squared terms and all pairwise interactions among them.
- They kept whichever model had the best fit on the training data and reported it as final.
What to cover in your answer
- Which clarifying questions you would ask before accepting the analysis, including whether the goal is prediction, inference, or causal estimation, and how each goal changes the right approach.
- Which assumptions actually matter for OLS and for valid inference, and why the shape of Y's marginal distribution is not one of them.
- Ways dwell-time data can break standard linear-model assumptions (skew, zeros, censoring, outliers, dependence).
- The problems caused by the exhaustive subset and interaction search, and why "best in-sample fit" is the wrong selection criterion.
- The diagnostics you would run instead.
- How you would redesign modeling and validation: baselines, data splitting or cross-validation, metrics, and alternatives such as target transformations, GLMs, regularization, robust or clustered standard errors, and tree-based models.
Hints
Hint 1
Count the candidate terms (main effects, squares, pairwise interactions) and the number of models in the search. Then ask what happens to R² and training error whenever a term is added.
Hint 2
Look at what the Gauss-Markov assumptions are about: errors conditional on X, not the marginal distribution of Y. Think of a binary predictor with a large effect and what that does to a histogram of Y.
Hint 3
Think about how the data were generated: bounces, timeouts, last-page time, repeated visits by the same user, and features recorded after the click. Each suggests a specific diagnostic or an alternative model.
Hint 4
For the redesign, think in this order: define the goal, set a simple baseline, split by user and time, choose a suitable target model, control complexity with penalization or CV, and report honest out-of-sample metrics.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Short verdict
The workflow has one false justification (Y looks normal), one built-in failure (selecting on training fit), and several risks specific to dwell-time data. I would not approve it as is.
1. Clarify before judging
Goal determines what "good" means:
| Goal | What matters | Consequence |
|---|---|---|
| Prediction | Out-of-sample error | Flexible terms, penalties, and trees are fine if validated honestly |
| Inference | Valid standard errors and interpretable coefficients | Pre-specify the model; data-driven selection invalidates p-values |
| Causal effect | Identification (confounding, selection) | Needs a causal design or experiment; fit quality is nearly irrelevant |
Data questions:
- What are X1 to X4? Numeric or categorical? Are any measured during or after the session (for example pages viewed)? That is leakage.
- What is a row: a session, a user, a query? Do users repeat?
- How are bounces, last-page time, timeouts, and outliers recorded or trimmed?
- What is n, and what population and time window does it cover?
2. Normality of Y is the wrong justification
The Gauss-Markov conditions are: linearity in parameters, full column rank, exogeneity E[ε | X] = 0, and spherical errors (constant variance, uncorrelated). OLS is then the best linear unbiased estimator. Normality is not on the list. Normal errors given X are needed only for exact small-sample t and F tests, and with large n the CLT makes inference approximately valid anyway.
The marginal distribution of Y mixes the signal and the noise. A strong binary predictor makes Y bimodal even with perfectly normal errors, and a normal-looking Y can still hide skewed or heteroskedastic residuals. Checks belong on residuals. Also, raw dwell time is almost never normal, so I would ask whether Y was already transformed, truncated, or filtered.
3. How dwell-time data strains the model
- Right skew and heavy tails: tabs left open create huge values that dominate a squared-error fit.
- Zeros and bounces: a point mass near zero suggests two processes (bounce or not, then duration).
- Censoring: last-page time is often unobserved and sessions time out, so durations are right-censored.
- Non-negativity: a linear model can predict negative seconds.
- Heteroskedasticity: variance usually grows with the mean.
- Dependence: repeat users, queries, and time-of-day effects cluster errors, so naive standard errors are too small.
- Selection: only people who clicked are observed, which limits generalization.
4. Why the search and the selection rule fail
Terms: 4 linear + 4 squared + 6 interactions = 14, so up to 2^14 = 16,384 models.
- In-sample fit always favors the biggest model. R² and training SSE never get worse when you add terms, so "best fit" just selects the full 14-term model. The search is pointless as a selection mechanism.
- Overfitting. Even with a penalized criterion, picking the best of thousands of models on one dataset fits noise, and training error is optimistically biased.
- Selective-inference bias. Reported p-values and intervals ignore the search; selected coefficients suffer a winner's curse and standard errors are too narrow.
- Multicollinearity. X and X² (uncentered) and interactions with their main effects are highly correlated, so coefficients are unstable.
- Hierarchy violations. Keeping X1·X2 without X1 and X2 makes the model depend on how variables are coded.
- Categorical variables. Squaring a dummy is meaningless, and multi-level interactions inflate the parameter count quickly.
5. Diagnostics I would run
- Functional form: residuals vs. fitted, partial-residual plots, spline fits.
- Heteroskedasticity: spread-vs-fitted plot, Breusch-Pagan; use HC3 robust standard errors if present.
- Error shape: Q-Q plot of residuals (not Y).
- Collinearity: VIF on centered terms, condition number.
- Influence: leverage, Cook's distance, DFBETAS, particularly for very long sessions.
- Dependence: intra-class correlation by user or query, autocorrelation over time.
- Leakage: check when each feature is recorded relative to the click; be suspicious of one feature dominating.
6. Redesigned process
Split properly. Hold out a test set touched once. Tune with cross-validation grouped by user and, if deployment is forward-looking, split by time, so the same user never sits in both train and validation.
Baselines first. Predict the mean or median, then fit an additive main-effects model. Every extra complexity must beat these on held-out data.
Model the target sensibly.
- OLS on log(Y + 1), with a smearing correction when back-transforming, since exp(E[log Y]) is not E[Y].
- Gamma or Tweedie GLM with a log link for positivity and mean-dependent variance.
- A hurdle model: logistic for bounce, Gamma or log-normal for duration given engagement.
- Survival or AFT models if censoring is material.
- Huber or other robust loss if extreme values are artifacts.
Control complexity deliberately. Center variables, then use ridge, lasso, or elastic net over the quadratic and interaction candidates with the penalty chosen by grouped CV. Alternatively use gradient-boosted trees, which find nonlinearity and interactions automatically, and interpret them with partial dependence or SHAP. Keep any interaction hierarchical.
Metrics. Report out-of-sample MAE or RMSE on the original scale, plus a rank or calibration check (predicted vs. observed by decile). MAE or median-based errors are preferable to RMSE when tails are heavy.
Inference. If coefficients matter, pre-specify a small model from domain knowledge, use cluster-robust standard errors by user, and bootstrap by cluster. If selection must be data-driven, do it on a separate split from the one used for inference.
Causal claims. Avoid them from observational fits. Draw the assumed causal graph, adjust for confounders, or run an experiment.
Common mistakes to avoid
- Justifying OLS by plotting Y rather than inspecting residuals.
- Treating training R² or a p-value after a search as evidence.
- Random row-level splits when users repeat.
- Ignoring leakage from post-click features.
- Exponentiating log-scale predictions and calling them means.
Summary line
"Normality of Y is irrelevant, training fit cannot pick a model, and the data are skewed, censored, and clustered. I would pin down the goal, build a simple baseline, split by user and time, use a log-link GLM or penalized and tree models with honest cross-validation, and use cluster-robust errors for any inference."