How do I get regression coefficients from a variance covariance matrix in R?
<p>I want to work out a multiple regression example all the way through using matrix algebra to calculate the regression coefficients. </p>

<pre><code>#create vectors -- these will be our columns
y &lt;- c(3,3,2,4,4,5,2,3,5,3)
x1 &lt;- c(2,2,4,3,4,4,5,3,3,5)
x2 &lt;- c(3,3,4,4,3,3,4,2,4,4)

#create matrix from vectors
M &lt;- cbind(y,x1,x2)
k &lt;- ncol(M) #number of variables
n &lt;- nrow(M) #number of subjects

#create means for each column
M_mean &lt;- matrix(data=1, nrow=n) %*% cbind(mean(y),mean(x1),mean(x2)); M_mean

#creates a difference matrix which gives deviation scores
D &lt;- M - M_mean; D

#creates the covariance matrix, the sum of squares are in the diagonal and the sum of cross products are in the off diagonals.  
C &lt;-  t(D) %*% D; C 
</code></pre>

<p>I can see what the final values should be (-.19, -.01) and what the matrices before this calculation look like. </p>

<pre><code>E&lt;-matrix(c(10.5,3,3,4.4),nrow=2,ncol=2)
F&lt;-matrix(c(-2,-.6),nrow=2,ncol=1)
</code></pre>

<p>But I'm not sure how to create these from the variance-covariance matrix to get the coefficients using matrix algebra. </p>

<p>Hope you can help. </p>