{"id":320,"date":"2018-11-30T12:00:28","date_gmt":"2018-11-30T10:00:28","guid":{"rendered":"http:\/\/benediktehinger.de\/blog\/science\/?p=320"},"modified":"2018-12-01T12:09:20","modified_gmt":"2018-12-01T10:09:20","slug":"interaction-and-effect-sum-coding","status":"publish","type":"post","link":"https:\/\/benediktehinger.de\/blog\/science\/interaction-and-effect-sum-coding\/","title":{"rendered":"Interaction and Effect\/Sum Coding"},"content":{"rendered":"<p>Some time ago I wrote a blog post on <a href=\"http:\/\/benediktehinger.de\/blog\/science\/dummy-coding-and-effects-coding\/\">dummy &amp; effect coding<\/a>. I made some new plots to visualize why the interaction in sum\/effect is coded as it is.<\/p>\n<p>Let&#8217;s take a typical 2&#215;2 design. We have two 2-level factors $A$ and $B$ and we also allow for an interaction.<br \/>\n$$y \\sim A + B + A:B$$<\/p>\n<p>We code A with -1 \/ 1 and B with -1 \/ 1 (depending on the level e.g. On=1, Off=-1)<\/p>\n<p>The interaction is coded as the multiplication of A and B: $A * B$. Therefore if $A$ and $B$ are both in the same level (both &#8220;off&#8221; or both &#8220;on&#8221;) we get a $+1$, else a $-1$.<\/p>\n<p><em>Side remark: This is different in dummy\/reference coding, where the interaction only codes what is extra if both A &amp; B are &#8220;on&#8221; (turns out that the magnitude of the interaction is just double &#8211; but this is a story for another time).<\/em><\/p>\n<p><a href=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-323\" src=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie.png\" alt=\"\" width=\"371\" height=\"528\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie.png 371w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-211x300.png 211w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><br \/>\nIn the first figure I added the main effects of $A$ and $B$ as Blue and Purple lines. The main effects in reference coding are relative to the means of the group means.<\/p>\n<p>In order to model the original data points, one needs to add the main effects and the interaction together:<br \/>\n<a href=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-321\" src=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-2.png\" alt=\"\" width=\"371\" height=\"528\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-2.png 371w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-2-211x300.png 211w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><\/p>\n<p>Notice that the way we have to add the interactions and main effects is exactly the multiplication I introduced earlier. That is, if we need to take -1 for $A$ and +1 for $B$, you bet we will need -1 for $A:B$.<\/p>\n<p>One way that I like to think about the interaction in effect coding is to think &#8220;What would be my prediction if there would be no interaction?&#8221;.<\/p>\n<p><a href=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-322\" src=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-3.png\" alt=\"\" width=\"371\" height=\"528\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-3.png 371w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2018\/11\/Zeichenfl\u00e4che-1-Kopie-3-211x300.png 211w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><\/p>\n<p>&#8220;What if there would be a model without interaction&#8221; is marked in black (it&#8217;s only using the main effects!). Note that the two black lines are parallel. Adding the red interaction-lines again helps us to move to the original datapoints.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago I wrote a blog post on dummy &amp; effect coding. I made some new plots to visualize why the interaction in sum\/effect is coded as it is. Let&#8217;s take a typical 2&#215;2 design. We have two 2-level factors $A$ and $B$ and we also allow for an interaction. $$y \\sim A + B + A:B$$ We code A with -1 \/ 1 and B with -1 \/ 1 (depending on the level e.g. On=1, Off=-1) The interaction is coded as the multiplication of A and B: $A * B$. Therefore if $A$ and $B$ are both in&#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-320","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/320","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=320"}],"version-history":[{"count":0,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"wp:attachment":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}