{"id":18,"date":"2013-09-05T01:00:54","date_gmt":"2013-09-05T01:00:54","guid":{"rendered":"http:\/\/sonny..ogi.edu\/~kgorman\/blog\/?p=18"},"modified":"2013-09-05T01:00:54","modified_gmt":"2013-09-05T01:00:54","slug":"loess-hyperparameters-without-tears","status":"publish","type":"post","link":"https:\/\/www.wellformedness.com\/blog\/loess-hyperparameters-without-tears\/","title":{"rendered":"LOESS hyperparameters without tears"},"content":{"rendered":"<p><a title=\"LOESS\" href=\"http:\/\/en.wikipedia.org\/wiki\/Local_regression\">LOESS<\/a> is a classic non-parametric regression technique. One potential issue that arises is that LOESS fits depend on several <i>hyperparameters<\/i> (i.e., parameters set by the experimenter <i>a priori<\/i>). In this post I&#8217;ll take a quick look at how to set these.<\/p>\n<p>At each point in a LOESS curve, the <i>y<\/i>-value is derived from a local, low-degree polynomial weighted regression. The first hyperparameter refers to the degree of the local fits. Most users set degree to 2 (i.e., use local quadratic curves), and with good reason. At degree 1, you&#8217;re just computing a local average. Higher degrees than 2 (e.g., cubic) tend to not have much of an effect.<\/p>\n<p>The other hyperparameter is &#8220;span&#8221;, which controls the degree of smoothing. A value of 0 uses no context and a value of 1 uses the entire sample (so it will be similar to fitting a single quadratic function to the data). The choice of this value has a major effect on the quality of the fit obtained:<\/p>\n<p><a href=\"https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-228\" src=\"https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu.png\" alt=\"gbu\" width=\"2100\" height=\"2100\" srcset=\"https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu.png 2100w, https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu-150x150.png 150w, https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu-300x300.png 300w, https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu-768x768.png 768w, https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu-1024x1024.png 1024w, https:\/\/www.wellformedness.com\/blog\/wp-content\/uploads\/2013\/09\/gbu-1200x1200.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>For the randomly generated data here, large values of the span parameter (&#8220;bad&#8221;) produce a LOESS which fails to follow the larger trend, whereas small values (&#8220;ugly&#8221;) primarily model noise. For this reason alone, the experimenter should probably not be permitted to select the span hyperparameter herself.<\/p>\n<p>Fortunately, there are several objectives used to determine an &#8220;optimal&#8221; setting for the span parameter. <a href=\"http:\/\/onlinelibrary.wiley.com\/doi\/10.1111\/1467-9868.00125\/abstract\">Hurvich et al. (1998)<\/a> propose a particularly privileged objective, namely minimizing <i>AIC<sub>C<\/sub><\/i>. This has been used to generate the &#8220;good&#8221; curve above. Here&#8217;s how I did it (adapted from <a href=\"https:\/\/stat.ethz.ch\/pipermail\/r-help\/2005-November\/082853.html\">this<\/a> post to R-help):<\/p>\n<script src=\"https:\/\/gist.github.com\/6444612.js\"><\/script>\n<p>There is also an R package <a href=\"http:\/\/cran.r-project.org\/web\/packages\/fANCOVA\/index.html\"><code>fANCOVA<\/code><\/a> which apparently includes a function <code>loess.as<\/code> which automatically determines the span parameter, presumably similar to how I&#8217;ve done it here. I haven&#8217;t tried it.<\/p>\n<p>PS to those inclined to care: the origins of memetic, snarky, academic &#8220;X without tears&#8221; is, to my knowledge,\u00a0<a title=\"J. Eric S. Thompson\" href=\"http:\/\/en.wikipedia.org\/wiki\/J._Eric_S._Thompson\">J. Eric S. Thompson<\/a>&#8216;s 1972 book\u00a0<em>Maya Hieroglyphs Without Tears<\/em>. While I have every reason to believe Thompson was poking fun at his detractors, it&#8217;s interesting to note that he turned out to be <a href=\"http:\/\/en.wikipedia.org\/wiki\/J._Eric_S._Thompson#Post_professional_life\">fabulously wrong about the nature of the hieroglyphs<\/a>.<em><br \/>\n<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LOESS is a classic non-parametric regression technique. One potential issue that arises is that LOESS fits depend on several hyperparameters (i.e., parameters set by the experimenter a priori). In this post I&#8217;ll take a quick look at how to set these. At each point in a LOESS curve, the y-value is derived from a local, &hellip; <a href=\"https:\/\/www.wellformedness.com\/blog\/loess-hyperparameters-without-tears\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;LOESS hyperparameters without tears&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[12,10],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-r","category-stats"],"_links":{"self":[{"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellformedness.com\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}