<?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 Re: nonlinear regression segmented linear models in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532230#M145827</link>
    <description>&lt;P&gt;You can explore the shape of the response (day) with a 2d spline fit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input RH	temp	Day;
datalines;
94	10	65
62	26	11
75	22	13
93	10	51
62	25	10
75	22	14
94	10	70
62	26	10
75	22	14
93	9	78
62	26	11
75	22	11
95	27	14
75	30	8
80	24	8
95	27	13
75	30	6
80	24	8
94	27	12
75	30	7
80	24	6
95	27	14
;

proc g3grid data=have out=haveg;
grid temp*rh=day / axis1=9 to 30 by 1 axis2=60 to 95 by 1 spline smooth=0.01;
run;

proc template;
 define statgraph contourplotparm;
   begingraph;
     entrytitle "Contour Plot of Day by temp and RH";
     layout overlay / xaxisopts=(griddisplay=on) yaxisopts=(griddisplay=on) ;
       contourplotparm x=temp y=RH z=day /
         contourtype=labeledline nhint=12 gridded=true;
     endlayout;
   endgraph;
 end;
run;

proc sgrender data=haveg template=contourplotparm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGRender13.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26779iD2FBD18E8E484C8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender13.png" alt="SGRender13.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 23:25:23 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-02-01T23:25:23Z</dc:date>
    <item>
      <title>nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532132#M145773</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options pageno=1 linesize=80;
goptions reset=all;
title "Model for digestive process in striped bass";
title2 "Wetzel and Kohler unpublished data";
data fishguts;
	input weight time;
	datalines;
1.000	0.0 
0.965	0.5 
0.723	3.0 
0.458	5.5 
0.245	8.0 
0.095	10.5 
0.065	13.0 
0.030	15.5 
0.012	18.0 
0.008	20.5 
0.000	23.0
;
run;
* Print data set;
proc print data=fishguts;
run;
* Sort x-axis data for plots;
proc sort data=fishguts;
	by time;
run;
* Plot data and fit smooth line;
proc gplot data=fishguts;
	plot weight*time;
	symbol1 i=sm50 v=star;
run;
* Nonlinear regression using joined linear + exponential model; 
proc nlin data=fishguts;
	* Models are joined at time = theta;
	if time&amp;lt;theta then                     
  		model weight=1+b*time; * Linear part of model;
	else                       
		model weight=(1+b*theta)*exp(d*(time-theta)); * Exponential part;
	* Initial guesses for parameter values;
	parms b=-0.15 to -0.05 by 0.02 theta=10 d=-0.30 to -0.10 by 0.02;
	* Boundaries for model parameters;
	bounds b d &amp;lt; 0;
	bounds theta &amp;gt;= 0;
	output out=resids p=pred r=resid;
run;
* Print data, fitted values, and residuls;
proc print data=resids;
run;
* Plot data and fitted model;
proc gplot data=resids;
	plot weight*time=1 pred*time=2 / overlay;
	symbol1 i=none v=star c=black;
	symbol2 i=j v=none c=blue;
run;
goptions reset=all;
title "Diagnostic plots for nonlinear regression assumptions";
* Plot residuals vs. predicted values;
proc gplot data=resids;
	plot resid*pred;
run;
* Normal quantile plot of residuals;
proc univariate noprint data=resids;
	qqplot resid / normal;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Greeting All&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use&amp;nbsp;nonlinear regression segmented linear models for the Day with temp and RH&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;I have this example and I need&amp;nbsp;help to make it fit to my data to predict the Day&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My Data is&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;RH&lt;/TD&gt;&lt;TD&gt;temp&lt;/TD&gt;&lt;TD&gt;Day&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;94&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;65&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;62&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;75&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;93&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;62&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;75&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;94&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;62&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;75&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&g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24&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 17:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532132#M145773</guid>
      <dc:creator>samer_badri75</dc:creator>
      <dc:date>2019-02-01T17:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532161#M145790</link>
      <description>&lt;P&gt;That must be a very old program! In&amp;nbsp;modern&amp;nbsp;SAS you can just turn&amp;nbsp;on ODS graphics and add PLOTS(UNPACK) to the PROC NLIN statement to get the fit plots, residual plots, and diagnostic plots created for you automatically!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The example has one explanatory&amp;nbsp;variable (time) and one response variable (weight). Thus it makes sense to fit a piecewise model to the growth/decay curve. In your day, you've provided two regressors (RH and Temp). How do you intend to fit a piecewise model? Also, DAY is a discrete variable. Do you intend to model it as a continuous variable, a count variable, or something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your goal is to model the response as a nonlinear function of two variables, I suggest &lt;A href="https://blogs.sas.com/content/iml/2016/03/23/nonparametric-regression-binary-response-sas.html" target="_self"&gt;a nonparametric regression procedure such as PROC &lt;/A&gt;GAMPL&lt;A href="https://blogs.sas.com/content/iml/2016/03/23/nonparametric-regression-binary-response-sas.html" target="_self"&gt;&amp;nbsp;or PROC ADAPTIVEREG.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 19:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532161#M145790</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-02-01T19:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532197#M145804</link>
      <description>&lt;P&gt;Many thanks for your quick reply and help.&lt;/P&gt;&lt;P&gt;I am trying to get an equation Day = X + or -&amp;nbsp;Xtemp + or -&amp;nbsp;XRH&lt;/P&gt;&lt;P&gt;When I run&amp;nbsp;multiple linear regression and I plot it, it showed it was not linear (between 10 and 22 it was shifted) that way I am trying to use&amp;nbsp;&lt;SPAN&gt;nonlinear regression segmented linear models.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a&amp;nbsp;code for&amp;nbsp;thatI can use it.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.PNG" style="width: 555px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26776i4D8F394F50B70F58/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.PNG" alt="1.PNG" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 20:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532197#M145804</guid>
      <dc:creator>samer_badri75</dc:creator>
      <dc:date>2019-02-01T20:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532230#M145827</link>
      <description>&lt;P&gt;You can explore the shape of the response (day) with a 2d spline fit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input RH	temp	Day;
datalines;
94	10	65
62	26	11
75	22	13
93	10	51
62	25	10
75	22	14
94	10	70
62	26	10
75	22	14
93	9	78
62	26	11
75	22	11
95	27	14
75	30	8
80	24	8
95	27	13
75	30	6
80	24	8
94	27	12
75	30	7
80	24	6
95	27	14
;

proc g3grid data=have out=haveg;
grid temp*rh=day / axis1=9 to 30 by 1 axis2=60 to 95 by 1 spline smooth=0.01;
run;

proc template;
 define statgraph contourplotparm;
   begingraph;
     entrytitle "Contour Plot of Day by temp and RH";
     layout overlay / xaxisopts=(griddisplay=on) yaxisopts=(griddisplay=on) ;
       contourplotparm x=temp y=RH z=day /
         contourtype=labeledline nhint=12 gridded=true;
     endlayout;
   endgraph;
 end;
run;

proc sgrender data=haveg template=contourplotparm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGRender13.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26779iD2FBD18E8E484C8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender13.png" alt="SGRender13.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 23:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532230#M145827</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-01T23:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532236#M145832</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;This code just shows the&amp;nbsp;&lt;SPAN&gt;shape, but did not show&amp;nbsp;the relationship, is it linear or nonlinear.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 00:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532236#M145832</guid>
      <dc:creator>samer_badri75</dc:creator>
      <dc:date>2019-02-02T00:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: nonlinear regression segmented linear models</title>
      <link>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532258#M145840</link>
      <description>&lt;P&gt;It's hard to tell from the data above. The design points are clustered, leaving vast areas of the design space uncovered.. It may look linear or not, depending on how much smoothing you apply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc g3grid data=have out=haveg;
grid temp*rh=day / axis1=9 to 30 by 1 axis2=60 to 95 by 1 spline smooth=0.01 1;
run;

proc sql;
create table haveGraph as
select unique
    a.*, 
    b.RH as RHpoint, 
    b.temp as tempPoint,
    b.day as dayPoint
from haveg as a left join 
    have as b on a.rh=b.rh and a.temp=b.temp
order by _smth_, rh, temp;
quit;

proc template;
 define statgraph contourplotparm;
   begingraph;
     entrytitle "Contour Plot of Day by temp and RH";
     layout overlay / xaxisopts=(griddisplay=on) yaxisopts=(griddisplay=on) ;
       contourplotparm x=temp y=RH z=day /
         contourtype=labeledline nhint=12 gridded=true;
       scatterplot x=tempPoint y=rhPoint / datalabel=dayPoint
        markerattrs=(symbol=circlefilled) jitter=auto;
     endlayout;
   endgraph;
 end;
run;

ods graphics / height=700 width=700;
proc sgrender data=haveGraph template=contourplotparm;
by _smth_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Shoothing = 0.01:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGRender24.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26789iFC92D98779522445/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender24.png" alt="SGRender24.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Smoothing = 1.0:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGRender25.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26790iE049DCB07258D30C/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender25.png" alt="SGRender25.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 04:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/nonlinear-regression-segmented-linear-models/m-p/532258#M145840</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-02T04:03:36Z</dc:date>
    </item>
  </channel>
</rss>

