Skip to contents

Source: Hedderich, Sachs and Reynarowych, Applied Statistics: Methods Using R, section 8.2.6, printed page 813, equations (8.36) and (8.37): yhat0 +/- t_{n-p-1, 1-alpha/2} sigma sqrt(1 + x0' (X'X)^-1 x0) and the same without the leading 1. (8.36) is the interval for a single future observation; (8.37) is the narrower interval for a mean future value, carrying no Var(epsilon) term. sigma is sqrt(RSS / (n - p - 1)) and p is the number of predictors excluding the intercept.

Usage

Lmpi(X, y, x0, level = 0.95, mean = FALSE)

Arguments

X

Design matrix INCLUDING its own leading column of ones.

y

Response, length nrow(X).

x0

New design row, same width as X and likewise starting at 1.

level

Confidence level.

mean

FALSE (default) gives (8.36); TRUE gives (8.37).

Value

list: fit, lower, upper, se_fit, sigma, df, tquant, leverage, coef, level, mean.

Details

The book worked example on the same page fits litter size on body weight and brain weight (n = 20, p = 2) and reports for x0 = c(1, 8.0, 0.4) the estimate yhat0 = 6.37 with 95% prediction interval 4.49 ... 8.24.

The design matrix is passed exactly as the book builds it, with its own leading column of ones, so that x0 is written the same way.

Examples

X <- cbind(1, 1:6); y <- c(2, 4, 5, 4, 6, 7)
Lmpi(X, y, c(1, 3))$fit
#> [1] 4.238095