<?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 Segmented regression plot or interrupted time series in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254949#M9237</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have similar data (just a small part of it):&lt;/P&gt;
&lt;P&gt;Rate time&lt;/P&gt;
&lt;P&gt;7.5 1&lt;/P&gt;
&lt;P&gt;7.4 2&lt;/P&gt;
&lt;P&gt;7.8 3&lt;/P&gt;
&lt;P&gt;7.2 4&lt;/P&gt;
&lt;P&gt;8.0 5&lt;/P&gt;
&lt;P&gt;7.9 6&lt;/P&gt;
&lt;P&gt;8.2 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I han information that there was a change in policy and it hapend when time=4. I want to plot in one graph rate*time and regression lines (before and after policy was introduce)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do it?&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2016 14:27:18 GMT</pubDate>
    <dc:creator>viollete</dc:creator>
    <dc:date>2016-03-07T14:27:18Z</dc:date>
    <item>
      <title>Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254949#M9237</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have similar data (just a small part of it):&lt;/P&gt;
&lt;P&gt;Rate time&lt;/P&gt;
&lt;P&gt;7.5 1&lt;/P&gt;
&lt;P&gt;7.4 2&lt;/P&gt;
&lt;P&gt;7.8 3&lt;/P&gt;
&lt;P&gt;7.2 4&lt;/P&gt;
&lt;P&gt;8.0 5&lt;/P&gt;
&lt;P&gt;7.9 6&lt;/P&gt;
&lt;P&gt;8.2 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I han information that there was a change in policy and it hapend when time=4. I want to plot in one graph rate*time and regression lines (before and after policy was introduce)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do it?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 14:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254949#M9237</guid>
      <dc:creator>viollete</dc:creator>
      <dc:date>2016-03-07T14:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254954#M9238</link>
      <description>&lt;P&gt;The way I would do it is to introduce a third column that grouped the data into "before" and "after" the policy change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rates;
length policy $ 6;
input rate time policy $;
cards;
7.5 1 before
7.4 2 before
7.8 3 before
7.2 4 before
8.0 5 after
7.9 6 after
8.2 7 after
;
run;

proc sgplot data=rates;
reg x=time y=rate / group=policy;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Mar 2016 14:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254954#M9238</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2016-03-07T14:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254959#M9239</link>
      <description>&lt;P&gt;Dan has the right idea.&amp;nbsp;For less coding,&amp;nbsp;you can create the indicator variable without changing the data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;policy = (time &amp;lt; 4);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 14:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/254959#M9239</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-03-07T14:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/255207#M9252</link>
      <description>&lt;P&gt;Thanks, it does not do what i want. I would like to see something as the Figure1a in the link below&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.cdc.gov/pcd/issues/2013/12_0268.htm" target="_blank"&gt;http://www.cdc.gov/pcd/issues/2013/12_0268.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 09:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/255207#M9252</guid>
      <dc:creator>viollete</dc:creator>
      <dc:date>2016-03-08T09:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/255225#M9255</link>
      <description>&lt;P&gt;You need to use a technique called &lt;A href="http://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html" target="_self"&gt;"scoring the regression model"&lt;/A&gt;&amp;nbsp;to add a new value to your data set. You want to add&amp;nbsp;an observation with coordinates x=Xmax&amp;nbsp;and y=(predicted value at XMax).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will require that you fit the model in one of the regression procedures, such as PROC GLM, and output the predicted value to a SAS data set.&amp;nbsp; The following code provides the main ideas:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rates;
input rate time;
group = (time&amp;lt;4);
cards;
7.5 1
7.4 2
7.8 3
7.2 4
8.0 5
7.9 6
8.2 7
;

/* create scoring observations with 
   x=XMax and Y=. for the group=1 */
data Fake;
rate=.; time=7; group=1;
run;

/* merge data sets */
data All;
set rates fake;
run;

/* evaluate model; create output data set that contains the
   new predicted value for XMax for group=1 */
proc glm data=All plots=fitplot;
class group;
model rate = time group;
output out=FitOut p=pred;
quit;

proc sgplot data=FitOut;
scatter x=time y=rate / group=group;
series x=time y=pred / group=group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Mar 2016 13:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/255225#M9255</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-03-08T13:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647667#M19884</link>
      <description>&lt;P&gt;If I have two separate regression lines on a segmented regression plot, how do I join the lines to show the level change?&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 03:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647667#M19884</guid>
      <dc:creator>ajames2020</dc:creator>
      <dc:date>2020-05-14T03:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647771#M19885</link>
      <description>&lt;P&gt;To join the lines, they need to be in the same group.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 12:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647771#M19885</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-05-14T12:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647805#M19886</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=import;

reg x=date y=y_variable/group=intervention;

run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Above is the code I'm using, and the goal is to show that after the intervention was implemented, there was a slope change. Essentially, the code above gave me two separate slopes: a pre intervention and a post-intervention slope, which is great. I want to connect the end of my pre-intervention slope to the start of my post-intervention slope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there another code that I can use for this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other thing I tried doing was to use proc autoreg to generate values for "ytrend" or the "predicted trend" according to the SAS support guide on proc autoreg. When I plotted that against the date, it was able to connect the separate lines the way I want it. However, the "ytrend" lines don't fit the data points/scatter points as well as the regression lines described earlier. My question is, in time series analysis, is the "ytrend" line the same as the "regression line" - are they analogous?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate your expert advice as I am clearly very new to SAS graphics.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647805#M19886</guid>
      <dc:creator>ajames2020</dc:creator>
      <dc:date>2020-05-14T13:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647815#M19887</link>
      <description>&lt;P&gt;The regression lines you are fitting by using the REG statement in PROC SGPLOT are similar to PROC GLM, not PROC AUTOREG. You can fit the model in PROC GLM, output the data, and then plot it any way you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* generate example data */
data import;
call streaminit(1);
retain intervention 0;
do x = 1 to 100;
   y = x + rand("Normal", 0, 3);
   if x &amp;gt; 50 then do;
      intervention = 1;
      y = y - 20;
   end;
   output;
end;
proc sgplot data=import;
reg x=x y=y /group=intervention;
run;
/********************************************************/
/* use PROC GLM to make the same predictions */
proc glm data=import plots=none;
class intervention;
model y = x | intervention;
output  out=ModelOut Predicted=Pred_Y;
run; 

proc sort data=ModelOut; by x; run;

proc sgplot data=ModelOut;
scatter x=x y=y /group=intervention;
series x=x y=Pred_y / lineattrs=(color=black);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 13:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647815#M19887</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-05-14T13:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647819#M19888</link>
      <description>Thank you! I will try the steps you proposed.</description>
      <pubDate>Thu, 14 May 2020 14:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647819#M19888</guid>
      <dc:creator>ajames2020</dc:creator>
      <dc:date>2020-05-14T14:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Segmented regression plot or interrupted time series</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647827#M19889</link>
      <description>This right here is why you're a true SAS expert. This is exactly what I needed! and it worked. Thank you!</description>
      <pubDate>Thu, 14 May 2020 14:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Segmented-regression-plot-or-interrupted-time-series/m-p/647827#M19889</guid>
      <dc:creator>ajames2020</dc:creator>
      <dc:date>2020-05-14T14:37:00Z</dc:date>
    </item>
  </channel>
</rss>

