Skip to contents

ESL Eq. (3.8), sigma^2 = RSS / (N - p - 1). The book is explicit about the denominator: N - p - 1 rather than N is what makes E(sigma^2_hat) = sigma^2. The p + 1 counts the slopes plus the intercept, so a design that already carries a column of ones must not be charged for it twice.

Usage

morie_esl_residual_variance(X, y, beta = NULL)

Arguments

X

design matrix, with or without a leading column of ones.

y

response.

beta

optional coefficients; least squares when NULL.

Value

list: value, sigma, rss, df, n, p, intercept_in_X, mle_variance, bias_factor, fitted, residuals, method.

Details

Dividing by N gives the maximum-likelihood estimator, biased downward by exactly (N-p-1)/N; both are returned. Eq. (3.11) adds (N-p-1) sigma^2_hat ~ sigma^2 chi^2_{N-p-1}.

References

Hastie, Tibshirani and Friedman (2009), Sec. 3.2, Eqs. (3.8) and (3.11).

Examples

set.seed(1)
X <- matrix(stats::rnorm(120), 40)
morie_esl_residual_variance(X, stats::rnorm(40))$df
#> [1] 36