How to find the exponential regression via SAS?
Unfortunately, proc nlin is not very generous in terms of fit diagnostics compared to, say, proc reg. You thus have to do your own calculations, as I did below for the R square and the AIC.
data test;
input y x;
datalines;
3.366 3
3.052 6
2.666 9
2.755 12
2.203 15
1.886 18
1.525 21
1.547 24
0.81 27
0.76 30
0.27 33
0.67 36
;
title "Corrected sum of squares";
proc sql;
select css(y) into :CSSy
from test;
quit;
title "Linear fit";
ods graphics / imagename="LinearFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = S0 - b*x;
ods output EstSummary=summLin;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summLin as N, summLin as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
title "Exponential fit";
ods graphics / imagename="ExponentialFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = S0 * exp( - b*x);
ods output EstSummary=summExp;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summExp as N, summExp as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
title """Square root"" fit";
ods graphics / imagename="SquareRootFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = (sqrt(S0) - b*x)**2;
ods output EstSummary=summSqrt;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summSqrt as N, summSqrt as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
R square and AIC are appropriate for comparing models in this case because the dependent data is the same and the number of fitted parameters is the same for the three models. Turns out that for this data, the linear model fits the best.
PG
PROC GENMOD and PROC GLIMMIX can fit models where the response is assumed to possess a probability distribution of the exponential form.
If exponential and square root refer to your model equation, i.e. you are trying to fit a non-linear model, then PROC NLIN will likely accomodate your needs.
PG
My data
y | x |
3.366 | 3 |
3.052 | 6 |
2.666 | 9 |
2.755 | 12 |
2.203 | 15 |
1.886 | 18 |
1.525 | 21 |
1.547 | 24 |
0.81 | 27 |
0.76 | 30 |
0.27 | 33 |
0.67 | 36 |
I am just a beginner, I know how to find linear (proc reg) but I don't know how to find the square root and exponential regression (nonlinear regression).
I would be glad if you kindly run these proc's on my data and send the calculation as an example to me.
Here is an example of fitting an exponential function to your data using non-linear regression :
data test;
input y x;
datalines;
3.366 3
3.052 6
2.666 9
2.755 12
2.203 15
1.886 18
1.525 21
1.547 24
0.81 27
0.76 30
0.27 33
0.67 36
;
proc nlin data=test plots=fit;
parameters a=1 b=-1;
model y = a*exp(b*x);
run;
Check out the output listing and the FitPlot graph.
PG
Thank you for your help.
Dearest sir, I run it and it works perfectly for exponential model. It means right now I can run linear model, and exponential model on SAS but what about square root model? I need to run the square model too on my data. Dearest sir, I have to run all these three models (together if possible otherwise separately) for my data using SAS.
*P.S The above exponential method doesn't produce any R2 value.
Many many thanks , kind of you
I don't know what you mean exactly by "square root model" for this data. Please explain. - PG
Not Sure. Maybe OP means f(x)=x^2
But look at the data. It is inversly proportional to x.
Here are the equations form of square root model, linear, and exponential. From this plate form with the help of you people I have learnt but now I want to also run square root model. Please have a look at the above picture.
Thanks alot
Unfortunately, proc nlin is not very generous in terms of fit diagnostics compared to, say, proc reg. You thus have to do your own calculations, as I did below for the R square and the AIC.
data test;
input y x;
datalines;
3.366 3
3.052 6
2.666 9
2.755 12
2.203 15
1.886 18
1.525 21
1.547 24
0.81 27
0.76 30
0.27 33
0.67 36
;
title "Corrected sum of squares";
proc sql;
select css(y) into :CSSy
from test;
quit;
title "Linear fit";
ods graphics / imagename="LinearFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = S0 - b*x;
ods output EstSummary=summLin;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summLin as N, summLin as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
title "Exponential fit";
ods graphics / imagename="ExponentialFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = S0 * exp( - b*x);
ods output EstSummary=summExp;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summExp as N, summExp as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
title """Square root"" fit";
ods graphics / imagename="SquareRootFit";
proc nlin data=test plots=fit;
parameters S0=1 b=0;
model y = (sqrt(S0) - b*x)**2;
ods output EstSummary=summSqrt;
run;
proc sql;
select N.nValue1 as n format=4.0,
SSE.nValue1 as SSE,
1 - SSE.nValue1/&CSSy as RSquare,
N.nValue1 * log(SSE.nValue1/N.nValue1) + 2*2 as AIC
from summSqrt as N, summSqrt as SSE
where N.Label1="Observations Used" and SSE.Label1="Objective";
quit;
R square and AIC are appropriate for comparing models in this case because the dependent data is the same and the number of fitted parameters is the same for the three models. Turns out that for this data, the linear model fits the best.
PG
Dearest sir,
I can;t express my happiness after running your suggested programming on SAS. It really works and fullfil my needs. I will just say wow excellent sir, hats off to you.
Many many thanks dearest sir.
Dearest sir,
These are the last two models remained. Could make the programming for these above two models too using my data.
In logistic model:
Y = % prey remaining in the stomach
A = estimated parameter
B = scale parameter
C = x-ordinate of the point of inflection of the curve
t = elapsed time after ingestion
In power exponential model:
Y = % prey remaining in the stomach
A = half life of decaying prey
B = shape coefficient
t = elapsed time after ingestion
Many many thanks dearest sir.
Hi PG Stats,
I am trying to learn about the exponential regression model and was guessing on how you determined the values "a=1 and b=b=-1" (parameters a=1 b=-1;). Are they from the dependant variable of the model? Can you please explain that for my understanding? Thank you
Fridge_wpg
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.