<?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: Running a sequence of non-linear regressions with different constants in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638169#M21538</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296354"&gt;@Vic3&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's strange that there should be no way to tell PROC NLIN that &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; is a constant and not a parameter. A workaround that I've just tested is: Create the BY variable as a character variable (say, &lt;FONT face="courier new,courier"&gt;Co&lt;STRONG&gt;c&lt;/STRONG&gt;&lt;/FONT&gt;) and adapt the MODEL statement correspondingly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model C = input(Coc,32.)*EXP(-k*time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or leave the MODEL statement unchanged and insert the definition of &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; before the MODEL statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Co=input(Coc,32.);
model C = Co*EXP(-k*time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This solution seems to be faster than a macro implementing your WHERE approach in a %DO loop (not surprisingly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 21:38:55 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-04-07T21:38:55Z</dc:date>
    <item>
      <title>Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638152#M21535</link>
      <description>&lt;P&gt;In my example below the equation is simplified and number of constants is reduced for clarity. I'm using SAS 9.4 x64.&lt;/P&gt;&lt;P&gt;Simple exponential decay function: C=Co*EXP(-k*time)&lt;/P&gt;&lt;P&gt;For any given Co there are multiple “time - C” data pairs (each Co representing a separate experiment). Namely:&lt;/P&gt;&lt;P&gt;Co&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.1&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.8&lt;/P&gt;&lt;P&gt;…&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.9&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.4&lt;/P&gt;&lt;P&gt;…&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to generate a series of regressions, one for each value of Co.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I manually type in Co value into the code, for example, C=5*EXP(-k*time), everything works fine.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics on / width=640PX height=480PX;
proc nlin data=example plots;
	parameters k=0.5;
	where Co = 5;
	model C = 5 * EXP(-k*time);
run;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I receive a graph of C vs time with raw data and a regression curve and correct numerical output (parameter estimates, etc.). Obviously, I get one regression at a time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I add Co as a variable (below), numerical output is identical to the previous approach, but strangely the graphs depict Co vs time instead (which happens to be a vertical line).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics on / width=640PX height=480PX;
proc nlin data=example plots;
	parameters k=0.5;
	by Co;
	model C = Co * EXP(-k*time);
run;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a simple way to fix this? I need to examine the graphs with data and regression line as well as numerical output. I don’t want to do one regression at a time, there are too many.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 19:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638152#M21535</guid>
      <dc:creator>Vic3</dc:creator>
      <dc:date>2020-04-07T19:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638156#M21536</link>
      <description>&lt;P&gt;Typically, C0 is a parameter that the model estimates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a nonlinear model; it is log-linear, which means&lt;/P&gt;
&lt;P&gt;Take log of both sides:&lt;/P&gt;
&lt;P&gt;log(Y) = log(C0) - K*T&lt;/P&gt;
&lt;P&gt;Define Z = log(Y). Then perform a linear regression for&lt;/P&gt;
&lt;P&gt;MODEL Z = T;&lt;/P&gt;
&lt;P&gt;and use the Intercept and estimate of the T variable to form the estimate for your exponential model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If, for some reason, you want to specify C0, then define W = log(Y/C0) and solve the no-intercept linear system&lt;/P&gt;
&lt;P&gt;MODEL W = T / NOINT;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 20:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638156#M21536</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-04-07T20:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638167#M21537</link>
      <description>&lt;P&gt;Thank you.&lt;BR /&gt;Co has to be specified. Unfortunately, I can't turn it into a linear model either. I simplified the equation for clarity.&lt;BR /&gt;I just want to loop through subsets of data, generating a sequence of equations.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 05:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638167#M21537</guid>
      <dc:creator>Vic3</dc:creator>
      <dc:date>2020-04-08T05:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638169#M21538</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296354"&gt;@Vic3&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's strange that there should be no way to tell PROC NLIN that &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; is a constant and not a parameter. A workaround that I've just tested is: Create the BY variable as a character variable (say, &lt;FONT face="courier new,courier"&gt;Co&lt;STRONG&gt;c&lt;/STRONG&gt;&lt;/FONT&gt;) and adapt the MODEL statement correspondingly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model C = input(Coc,32.)*EXP(-k*time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or leave the MODEL statement unchanged and insert the definition of &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; before the MODEL statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Co=input(Coc,32.);
model C = Co*EXP(-k*time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This solution seems to be faster than a macro implementing your WHERE approach in a %DO loop (not surprisingly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 21:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638169#M21538</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-07T21:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638191#M21539</link>
      <description>&lt;P&gt;That works to produce numerical output, but not graphs. SAS finds parameters correctly either way, but for some reason plots time vs Co (a constant) instead of C vs time. Should plot statement be modified?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 00:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638191#M21539</guid>
      <dc:creator>Vic3</dc:creator>
      <dc:date>2020-04-08T00:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638250#M21542</link>
      <description>&lt;P&gt;I had tested my code and it produced exactly the same correct five graphs as with a WHERE condition -- without changing your code w.r.t. plot requests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key is that the input dataset &lt;EM&gt;does not contain a numeric variable &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt;&lt;/EM&gt;&amp;nbsp;(unless it is not used in the MODEL statement anyway). I suspect that you didn't drop it from your input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that in my first suggestion (&lt;FONT face="courier new,courier"&gt;model C = input(Coc,32.)*EXP(-k*time);&lt;/FONT&gt;) a variable &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; is not even mentioned, so it's &lt;EM&gt;impossible&lt;/EM&gt; that SAS "&lt;SPAN&gt;plots time vs Co (a constant)."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In my second suggestion, &lt;FONT face="courier new,courier"&gt;Co&lt;/FONT&gt; is defined only in the PROC NLIN step. If it is &lt;EM&gt;not&lt;/EM&gt; contained in the input dataset (this is important), the procedure will not treat this variable as a parameter.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 08:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638250#M21542</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-08T08:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Running a sequence of non-linear regressions with different constants</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638273#M21545</link>
      <description>&lt;P&gt;Regression procedures assume that a column in the data set that is involved in the model is a variable. In your case, you have a variable that has no variance, it is a constant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to handle this problem is to transform the variables (rescale) to incorporate the constant. For example,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Co        time      C;
datalines;
5          0          5
5          1          3.1
5          2          1.8
5          3          0.3
8          0          8
8          1          5.9
8          2          4.4
8          3          3.2
;

proc sort data=Have;
by Co Time;
run;

data Want;
set Have;
by Co; 
ScaledC = C / Co;
run;

proc nlin data=Want plots=Fit;
	parameters k=0.5;
	by Co;
	model ScaledC = EXP(-k*time);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 10:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Running-a-sequence-of-non-linear-regressions-with-different/m-p/638273#M21545</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-04-08T10:22:44Z</dc:date>
    </item>
  </channel>
</rss>

