<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic GAM with binary or categorical interaction in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649416#M194691</link>
    <description>&lt;P&gt;Hi all. In a Generalized Additive Model with a continuous predictor, is it possible to include interaction by a binary or categorical predictor? I know that in Proc GAM including&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;spline2(x1, x2)&lt;/PRE&gt;&lt;P&gt;will run a thin-plate spline with a nice graph showing interaction between two continuous predictors. Is there anything analogous for a binary/categorical interaction predictor? I hope I don't have to do this in R! Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2020 00:06:27 GMT</pubDate>
    <dc:creator>kpberger</dc:creator>
    <dc:date>2020-05-21T00:06:27Z</dc:date>
    <item>
      <title>GAM with binary or categorical interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649416#M194691</link>
      <description>&lt;P&gt;Hi all. In a Generalized Additive Model with a continuous predictor, is it possible to include interaction by a binary or categorical predictor? I know that in Proc GAM including&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;spline2(x1, x2)&lt;/PRE&gt;&lt;P&gt;will run a thin-plate spline with a nice graph showing interaction between two continuous predictors. Is there anything analogous for a binary/categorical interaction predictor? I hope I don't have to do this in R! Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 00:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649416#M194691</guid>
      <dc:creator>kpberger</dc:creator>
      <dc:date>2020-05-21T00:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: GAM with binary or categorical interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649521#M194738</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 10:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649521#M194738</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-21T10:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: GAM with binary or categorical interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649687#M194817</link>
      <description>&lt;P&gt;If you just want to include a constant shift the depends on a CLASS variable, you can use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CLASS A;&lt;/P&gt;
&lt;P&gt;model y = param(A) ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, it sounds like you want to include interaction terms between a continuous and a classification variable. I don't think PROC GAMPL does that automatically, but you can &lt;A href="https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html" target="_self"&gt;use a SAS procedure to generate the design matrix that includes the interaction effects&lt;/A&gt; or you&amp;nbsp; can create them manally. You can&amp;nbsp;then include spline terms for those interaction effects. For example, here is some fake data in which the response depends on the class levels:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MyData;
do x = 1 to 10 by .1;
   group="A"; y = 2*x + sin(x) + rand("Normal"); output;
   group="B"; y = 10 - x - sin(x) + rand("Normal"); output;
end;
run;

data Have; 
set MyData; 
x_A = x*(group='A'); /* manually create the interaction terms */
x_B = x*(group='B');
run;

proc gampl data=Have plots=components;
class group;&lt;BR /&gt;model Y = param(group | x) spline(x_A) spline(x_B);  /* semiparametric */&lt;BR /&gt;/* model Y = spline(x_A) spline(x_B);   *or pure parametric; */
output out=GamPLOut pred=p;
id Y X group;
run;

proc sort data=GamPLOut;
by group x;
run;

proc sgplot data=GamPLOut;
scatter x=x y=y / group=group;
series x=x y=p / group=group;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 May 2020 19:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649687#M194817</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-05-21T19:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: GAM with binary or categorical interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649739#M194833</link>
      <description>&lt;P&gt;Thank you for such a complete answer! This works perfectly. Would you mind telling me what the ID statement adds? I'm curious as to what it does.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 23:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649739#M194833</guid>
      <dc:creator>kpberger</dc:creator>
      <dc:date>2020-05-21T23:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: GAM with binary or categorical interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649742#M194834</link>
      <description>&lt;P&gt;Yay! Glad it satisfies your needs.&lt;/P&gt;
&lt;P&gt;In traditional SAS procedures, the OUTPUT statement automatically copies all variables in the input data to the output data set. This can be expensive with large data, so the newer predictive modeling procedures only write out the variables you request. The predictions, residuals, CLs, etc are specified on the OUTPUT statement. If you want to copy any variables from the input data, you use the ID statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the ID statement so that I could plot the original data in the SGPLOT call. An alternative is to merge the predicted values (in GAMPLOut) and the original data in a separate DATA step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 23:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GAM-with-binary-or-categorical-interaction/m-p/649742#M194834</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-05-21T23:25:18Z</dc:date>
    </item>
  </channel>
</rss>

