# OLS regression from first principles

I'm trying to work out how you do this from first principles. The Wikipedia page on linear regression gives me enough to solve it with matrix operations through the origin but I can't find much literature on implementing an algorithm for an OLS fit returning coefficients, a t-statistic and an $r^2$ value for the fit

Can anyone point me to good reference?

Thanks

• Is the question about understanding the mathematics and/or mathematical formulas behind the mentioned quantities or is it about numerical algorithms to actually compute them? Strangely enough, they're very different questions. – cardinal Nov 5 '11 at 21:43
• Both really. I'm primarily in need of implementing it, but I would like to understand the maths properly too. – Chris Nov 5 '11 at 22:38
• Let me ask a question so that I understand yours better: Why do you need to implement it yourself? There are (many!) very good reasons not to do so, and instead to rely on available libraries and/or software packages with many tens (or hundreds) of thousands of man-hours already put into them. – cardinal Nov 5 '11 at 22:58
• For the mathematical and statistical background of linear regression, any good linear-regression theory text will do. Here is a recent question where three are mentioned. – cardinal Nov 5 '11 at 23:03
• Well, one because I feel implementing anything is a great way to understand it properly, and two because I can't find an existing implementation for the platform I require it. – Chris Nov 6 '11 at 10:28