Statistical Model Diagnostics
Instruction: Discuss the methods for diagnosing the fit of a statistical model in R, including residual analysis and goodness-of-fit tests.
Context: This question assesses the candidate's understanding of model evaluation techniques, critical for validating the assumptions and accuracy of statistical models.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Match diagnostics to the model and the intended use. For a Gaussian linear model, inspect residual-versus-fitted patterns, scale changes, Q-Q behavior and influential observations; also examine residual ordering when dependence is possible.
fit <- lm(mpg ~ wt + hp, data = mtcars) diagnostics <- data.frame(fitted = fitted(fit), residual = residuals(fit), leverage = hatvalues(fit), cook = cooks.distance(fit)) stopifnot(nrow(diagnostics) == nrow(mtcars),...