R/vcovhat.R
vcovhatbetahat.Rd
Calculates the variance-covariance matrix of estimates of regression coefficients using $$ \widehat{\mathrm{cov}} \left( \boldsymbol{\hat{\beta}} \right) = \hat{\sigma}_{\varepsilon}^2 \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} $$ where \(\hat{\sigma}_{\varepsilon}^{2}\) is the estimate of the error variance \(\sigma_{\varepsilon}^{2}\) and \(\mathbf{X}\) is the data matrix, that is, an \(n \times k\) matrix of \(n\) observations of \(k\) regressors, which includes a regressor whose value is 1 for each observation on the first column.
vcovhatbetahat(X, y)
X |
|
---|---|
y | Numeric vector of length |
Returns the variance-covariance matrix of estimates of regression coefficients.
Wikipedia: Ordinary Least Squares
Other variance-covariance of estimates of regression coefficients functions:
.vcovhatbetahatbiased()
,
.vcovhatbetahat()
,
vcovhatbetahatbiased()
Ivan Jacob Agaloos Pesigan
# Simple regression------------------------------------------------ X <- jeksterslabRdatarepo::wages.matrix[["X"]] X <- X[, c(1, ncol(X))] y <- jeksterslabRdatarepo::wages.matrix[["y"]] vcovhatbetahat(X = X, y = y)#> [,1] [,2] #> [1,] 0.52850144 -0.0127611411 #> [2,] -0.01276114 0.0003363964# Multiple regression---------------------------------------------- X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] vcovhatbetahat(X = X, y = y)#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1.031824973 -7.772168e-02 -0.0850088949 -0.003619161 -0.0614813339 #> [2,] -0.077721683 1.329450e-01 -0.0087891568 0.016488857 0.0006878221 #> [3,] -0.085008895 -8.789157e-03 0.2592719536 -0.024507175 0.0032732863 #> [4,] -0.003619161 1.648886e-02 -0.0245071750 0.256115033 -0.0012904110 #> [5,] -0.061481334 6.878221e-04 0.0032732863 -0.001290411 0.0043433655 #> [6,] -0.007374837 6.863371e-05 0.0005654479 -0.001309463 0.0001995978 #> [,6] #> [1,] -7.374837e-03 #> [2,] 6.863371e-05 #> [3,] 5.654479e-04 #> [4,] -1.309463e-03 #> [5,] 1.995978e-04 #> [6,] 2.575241e-04