{"id":19009,"date":"2016-12-06T19:48:58","date_gmt":"2016-12-06T19:48:58","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=19009"},"modified":"2016-12-06T19:48:58","modified_gmt":"2016-12-06T19:48:58","slug":"linear-algebra-best-fit-line-method-of-least-squares-by-hand","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/linear-algebra-best-fit-line-method-of-least-squares-by-hand\/","title":{"rendered":"Linear algebra:  best fit line:  method of least squares by hand"},"content":{"rendered":"<h1>The tutor shows a nice trick to obtain a least squares line using matrix algebra.<\/h1>\n<p>In my <a href=\"?p=18885\">Nov 25<\/a> post I mentioned how, with Excel or LibreOffice Calc, to get a best-fit line for<\/p>\n<table style=\"width:20%;margin:auto;\">\n<tr>\n<td>x<\/td>\n<td>y<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>12<\/td>\n<\/tr>\n<\/table>\n<p>The same line can be gotten by hand, with the following ideas:<\/p>\n<ol>\n<li>\nImagining the best fit line to be of form y=mx+b, the table above can be related as the matrix equation<br \/>\n<img decoding=\"async\" src=\"\/..\/images\/best_fit_matrix_eqn_0_dec6.png\" style=\"display:block;margin:auto\" \/><\/li>\n<li>We multiply each side by the transpose matrix:<br \/>\n<img decoding=\"async\" src=\"\/..\/images\/transpose_mult_dec6.png\" style=\"display:block;margin:auto\" \/><\/li>\n<li>Performing the multiplication on each side yields<br \/>\n<img decoding=\"async\" src=\"\/..\/images\/matrix_part_three_dec6.png\" style=\"display:block;margin:auto\" \/><\/li>\n<p>which means<\/p>\n<p><img decoding=\"async\" src=\"\/..\/images\/equation_dec6.png\" style=\"display:block;margin:auto\" \/><\/li>\n<p>Solving, we get m=1.15, b=2.9:  our best-fit line is y=1.15x + 2.9, same with the result from <a href=\"?p=18885\">November 25<\/a> using a spreadsheet.<\/p>\n<p>Neat, eh?<\/p>\n<p>Source:<\/p>\n<p>Johnson\/Riess\/Arnold.  <u>Introduction to Linear Algebra<\/u>, Second Ed.  Don Mills:  Addison-Wesley, 1989.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor shows a nice trick to obtain a least squares line using matrix algebra. In my Nov 25 post I mentioned how, with Excel or LibreOffice Calc, to get a best-fit line for x y 0 3 2 5 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/linear-algebra-best-fit-line-method-of-least-squares-by-hand\/\"> <span class=\"screen-reader-text\">Linear algebra:  best fit line:  method of least squares by hand<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,302,3,7],"tags":[2047,2049,2048,2058,2057],"class_list":["post-19009","post","type-post","status-publish","format-standard","hentry","category-chemistry","category-linear-algebra","category-math","category-physics","tag-best-fit-line","tag-data-fitting","tag-least-squares-line","tag-least-squares-line-by-hand","tag-method-of-least-squares"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=19009"}],"version-history":[{"count":14,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19009\/revisions"}],"predecessor-version":[{"id":19023,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19009\/revisions\/19023"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=19009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=19009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=19009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}