{"id":368,"date":"2011-11-09T11:47:48","date_gmt":"2011-11-09T15:47:48","guid":{"rendered":"http:\/\/web.colby.edu\/mgimond\/?p=368"},"modified":"2011-11-09T11:47:48","modified_gmt":"2011-11-09T15:47:48","slug":"r-does-regression-make-sense-the-area-vs-perimeter-example","status":"publish","type":"post","link":"https:\/\/web.colby.edu\/mgimond\/2011\/11\/09\/r-does-regression-make-sense-the-area-vs-perimeter-example\/","title":{"rendered":"R: Does Regression make sense? The area vs. perimeter example"},"content":{"rendered":"<p>This is an example from the book \u00a0<a href=\"http:\/\/books.wwnorton.com\/books\/detail.aspx?ID=11597\">Statistics <\/a>(3rd Edition by Freedman, Pisani and Purves) where the authors remind the reader \u00a0&#8220;&#8230;even if the association [between variables] looks linear&#8230; [does] the regression make sense?&#8221;. \u00a0 As an example, they show how the correlation between area and perimeter is strong, yet this regression is &#8220;&#8230;silly. \u00a0The investigator should have looked at the two other variables, length and width&#8230;&#8221; which determine both area and perimeter.<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n&lt;pre&gt;# Generate random rectangles with dimensions ranging\r\n# from 1 to 8 units\r\na =  runif(50,1,8)\r\nb =  runif(50,1,8)\r\narea = a * b\r\nperim = 2 * (a + b)\r\n\r\n# Plot Area vs Perimeter\r\nplot(area ~ perim,pch=19,col=&quot;bisque2&quot;)\r\n\r\n# Run a regression model\r\nmodel = lm(area ~ perim)\r\nabline(model,col=&quot;blue&quot;)\r\nm.cor = round(cor(area,perim),digits=2)\r\nx.txt = 0.2 * (max(range(perim)) -  min(range(perim))) + min(range(perim))\r\ny.txt = 0.9 * (max(range(area)) -  min(range(area))) + min(range(area))\r\n\r\ntext(x.txt,y.txt,substitute(R^2 == A, list(A = m.cor)))\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/11\/Rplot11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-373\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/11\/Rplot11.png\" alt=\"\" width=\"482\" height=\"521\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/11\/Rplot11.png 482w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/11\/Rplot11-277x300.png 277w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an example from the book \u00a0Statistics (3rd Edition by Freedman, Pisani and Purves) where the authors remind the reader \u00a0&#8220;&#8230;even if the association [between variables] looks linear&#8230; [does] the regression make sense?&#8221;. \u00a0 As an example, they show how the correlation between area and perimeter is strong, yet this regression is &#8220;&#8230;silly. \u00a0The [&hellip;]<\/p>\n","protected":false},"author":1199,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12807],"tags":[],"_links":{"self":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/368"}],"collection":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/users\/1199"}],"replies":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":8,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/368\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}