This function performs ordinary least squares (OLS) regression, estimating the coefficients that best fit the response variable \(Y\) given the predictor matrix \(X\). The fitted values \(\hat{Y}\) are then returned.

ols.recovery(Y, X)

Arguments

Y

A numeric vector representing the response variable.

X

A numeric matrix or data frame representing the predictor variables. The function removes any duplicated columns from X.

Value

A numeric vector \(\hat{Y}\) containing the fitted values from the OLS regression.

Details

The function first converts the input matrix X to a data frame to remove any duplicate columns, ensuring that the matrix used for regression is unique in terms of predictors. It then applies OLS regression by solving the normal equations to estimate the coefficients \(\beta\). The fitted values \(\hat{Y}\) are computed as \(X \beta\).

See also