R/yhat.R
yhat.Rd
Calculates y-hat \(\left( \mathbf{\hat{y}} \right)\), that is, the predicted value of \(\mathbf{y}\) given \(\mathbf{X}\) using $$ \mathbf{\hat{y}} = \mathbf{X} \boldsymbol{\hat{\beta}}. $$
yhat(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"]] yhat <- yhat(X = X, y = y) hist(yhat)# Multiple regression---------------------------------------------- X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] yhat <- yhat(X = X, y = y) hist(yhat)