{"id":473,"date":"2022-04-21T15:10:50","date_gmt":"2022-04-21T13:10:50","guid":{"rendered":"https:\/\/benediktehinger.de\/blog\/science\/?p=473"},"modified":"2022-04-21T15:10:51","modified_gmt":"2022-04-21T13:10:51","slug":"modelling-circular-effects-using-splines","status":"publish","type":"post","link":"https:\/\/benediktehinger.de\/blog\/science\/modelling-circular-effects-using-splines\/","title":{"rendered":"Modelling Circular Effects using Splines"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/grafik.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/grafik.png\" alt=\"\" class=\"wp-image-474\" width=\"606\" height=\"281\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/grafik.png 986w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/grafik-300x139.png 300w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/grafik-768x356.png 768w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/a><figcaption>ERP effect of absolute angle between two saccades. <a href=\"https:\/\/jov.arvojournals.org\/article.aspx?articleid=2772164\">Dimigen &amp; Ehinger 2021<\/a> <\/figcaption><\/figure><\/div>\n\n\n\n<p><em>Note: This blog is just explaining the basis sets, not how to actually fit models \/ get parameters etc. <\/em><\/p>\n\n\n\n<p>Recently, we used the <a href=\"http:\/\/www.unfoldtoolbox.org\">unfoldtoolbox<\/a> (Matlab or Julia; access it from python!) to analyze some fixation-related ERPs. The approach we used (multiple regression with deconvolution) allowed us to include this circular-predictor: absolute saccade-angle. <\/p>\n\n\n\n<p>Why can&#8217;t we model saccade-angle using a linear predictor? The issue is straightforward: Look at this plot.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_pred_linear-1.png\"><img decoding=\"async\" src=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_pred_linear-1.png\" alt=\"\" class=\"wp-image-477\" width=\"-37\" height=\"-26\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_pred_linear-1.png 570w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_pred_linear-1-300x217.png 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/a><figcaption>Predicting <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">circular data<\/mark> with a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">straight line<\/mark> is difficult.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Ok, why can&#8217;t we use a standard non-linear spline regression?<\/p>\n\n\n\n<p>Wait &#8211; what even is a standard non-linear spline regression? Great that you asked. Instead of fitting a straight line with parameters slope &amp; intercept (think<em> y = m*x + c<\/em>), we can split up the x-axis regressor in multiple &#8220;local&#8221; regressors. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dfzljdn9uc3pi.cloudfront.net\/2019\/7838\/1\/fig-5-2x.jpg\" alt=\"\" width=\"679\" height=\"252\"\/><figcaption>Taken from Ehinger &amp; Dimigen 2019<\/figcaption><\/figure><\/div>\n\n\n\n<p>But: The angle starts at x=0, and goes to x=360 &#8211; but we all know, x=0 and x=360 are actually identical! The orange line added to the plot would have 0 &amp; 360 at different values, except for a slope of 0.<\/p>\n\n\n\n<p> How do we fix this, how do we &#8220;wrap around&#8221; the predictor axis?<\/p>\n\n\n\n<p><strong>Circular Splines!<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_1d.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_1d.png\" alt=\"\" class=\"wp-image-479\" width=\"406\" height=\"305\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_1d.png 560w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_1d-300x225.png 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/a><figcaption>We use a basis function that wraps around 0 \/ 360\u00b0<\/figcaption><\/figure><\/div>\n\n\n\n<p>Instead of having basis functions that have bounds at 0 \/ 360\u00b0, we are using a basis function set that wraps the circular space. If the idea didn&#8217;t become clear, here is an alternative visualization:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/lin_splines_2d-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/lin_splines_2d-1.png\" alt=\"\" class=\"wp-image-480\" width=\"452\" height=\"328\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/lin_splines_2d-1.png 570w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/lin_splines_2d-1-300x217.png 300w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/a><figcaption>&#8220;default&#8221; splines, spanning 0 to 1 or 0 to 360\u00b0<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_2d.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_2d.png\" alt=\"\" class=\"wp-image-481\" width=\"476\" height=\"370\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_2d.png 550w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2022\/04\/circ_splines_2d-300x233.png 300w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/a><figcaption>Circular splines &#8211; spanning 0 &#8211; 1 in a circular fashion. Note the first spline (second column) that is &#8220;active&#8221; both at 0 and at 1 (aka 0\u00b0 and 360\u00b0).<\/figcaption><\/figure><\/div>\n\n\n\n<p>Hopefully, these visualizations help some of you to understand circular splines better!<\/p>\n\n\n\n<p>Disclaimer: Thanks to Judith Schepers for discussing this with me; sorry for the typos etc. I am a bit in a rush<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This blog is just explaining the basis sets, not how to actually fit models \/ get parameters etc. Recently, we used the unfoldtoolbox (Matlab or Julia; access it from python!) to analyze some fixation-related ERPs. The approach we used (multiple regression with deconvolution) allowed us to include this circular-predictor: absolute saccade-angle. Why can&#8217;t we model saccade-angle using a linear predictor? The issue is straightforward: Look at this plot. Ok, why can&#8217;t we use a standard non-linear spline regression? Wait &#8211; what even is a standard non-linear spline regression? Great that you asked. Instead of fitting a straight line with&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:attachment":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}