Calculates y-hat \(\left( \mathbf{\hat{y}} \right)\), that is, the predicted value of \(\mathbf{y}\) given \(\mathbf{X}\) using $$ \mathbf{\hat{y}} = \mathbf{P} \mathbf{y} $$ where $$ \mathbf{P} = \mathbf{X} \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} \mathbf{X}^{T} . $$
Py(X, y)
X |
|
---|---|
y | Numeric vector of length |
Returns y-hat \(\left( \mathbf{\hat{y}} \right)\).
Wikipedia: Ordinary Least Squares
Ivan Jacob Agaloos Pesigan
# Simple regression------------------------------------------------ X <- jeksterslabRdatarepo::wages.matrix[["X"]] X <- X[, c(1, ncol(X))] y <- jeksterslabRdatarepo::wages.matrix[["y"]] Py <- Py(X = X, y = y) hist(Py)# Multiple regression---------------------------------------------- X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] Py <- Py(X = X, y = y) hist(Py)