Hello,
I'm currently working on a model to estimate different parameters about germinating fungi. I've already successfully estimated the slope at the inflection point of the data using the estimated result for its first derivation at the zero value of the second derivation.
For better visualization, I would like to transfer this value into an angle using the function atan(slope). Sadly I'm not able to transfer the result from a value in radians to degrees. I've tried to use the 'degrees' statement but It doesn't work the way I've used it (tried different variations).
I'm using SAS Studio 3.8
Any suggestions?
Thanks for your help!
Here is the used code:
The line I'm referring to is 115 estimate 'angle of slope inflection'
data fungi;
input time germrate;
datalines;
9 0
9 0
9 0
9 0
9 0
9 0
9 0
9 0
12 1
12 1
12 1
9 1
12 2
12 3
12 4
12 4
12 5
12 5
15 11
15 18
15 20
15 21
9 22
15 24
15 27
15 27
9 28
9 28
9 29
9 31
9 33
15 34
15 37
18 43
18 45
18 52
18 52
18 54
15 55
18 58
18 58
18 63
18 71
21 72
12 73
21 74
12 74
12 76
12 76
12 77
21 78
15 79
12 80
21 81
15 82
21 83
21 84
21 84
24 85
15 85
24 86
21 86
24 87
21 87
21 87
24 88
24 90
24 90
24 90
21 90
18 90
18 91
15 91
24 92
24 92
21 92
21 92
21 92
18 92
24 93
24 93
18 93
15 93
24 94
24 94
24 95
24 96
18 96
21 97
18 98
;
proc nlin data=fungi;
parms Pmax=98 tau=15 ;d=5 ;
model germrate = Pmax*(1-(1/(1+((time/tau)**d))));
run;
proc nlin data=fungi method=newton;
parameters Pmax=98 tau=15 ;d=5 ;
x=(tau*(((d-1)/(d+1)))**(1/d));
model germrate = Pmax*(1-(1/(1+((time/tau)**d))));
output out=nlinout predicted=pred l95m=l95mean u95m=u95mean l95=l95ind u95=u95ind;
estimate 'slope tau' (d*Pmax*((tau/tau)**d)/(tau*((((tau/tau)**d)+1)**2)));
*/ estimate 'slope turning' (d*Pmax*((x/tau)**d)/(x*((((x/tau)**d)+1)**2))) ;
estimate 'slope inflection' (d*Pmax*(((tau*(((d-1)/(d+1)))**(1/d))/tau)**d)/((tau*(((d-1)/(d+1)))**(1/d))*(((((tau*(((d-1)/(d+1)))**(1/d))/tau)**d)+1)**2))) ;
estimate 'angle of slope inflection' (select degrees(atan((d*Pmax*(((tau*(((d-1)/(d+1)))**(1/d))/tau)**d)/((tau*(((d-1)/(d+1)))**(1/d))*(((((tau*(((d-1)/(d+1)))**(1/d))/tau)**d)+1)**2)))))) ;
run;
proc print data=nlinout;
run;
data filler;
do time = 0 to 96 by 2;
predict=1;
output;
end;
run;
data fitthis;
set fungi filler;
run;
proc nlin data=fitthis method=newton;
parameters Pmax=98 tau=15 ;d=5 ;
model germrate = Pmax*(1-(1/(1+((time/tau)**d))));
output out=nlinout predicted=pred l95m=l95mean u95m=u95mean;
run;
proc print data=nlinout(where=(predict=1)); run;
proc sort data = nlinout;
by time;
run;
proc sgplot data=nlinout;
band upper=u95mean lower=l95mean x=time;
scatter x=time y=germrate;
series x=time y=pred;
run;
Hello @RobinN,
The conversion factor from radians to degrees is 180/p. So I'd write
estimate 'angle of slope inflection' 180/constant('pi')*atan(...);
Hello @RobinN,
The conversion factor from radians to degrees is 180/p. So I'd write
estimate 'angle of slope inflection' 180/constant('pi')*atan(...);
Hi @FreelanceReinh , @RobinN
If you are using SAS 9.4, there is also a new DEGREES function available.
@ErikLund_Jensen wrote:
Hi @FreelanceReinh , @RobinN
If you are using SAS 9.4, there is also a new DEGREES function available.
This is apparently what the OP tried to use. However, as long as this function is (strangely enough) only available in FedSQL, I think there's nothing easier than the manual conversion if you need it in a different procedure such as PROC NLIN.
I think the formulas in the ESTIMATE statements can be simplified substantially: In addition to several redundant pairs of parentheses there are many factors tau cancelling out (most obviously in "(tau/tau)") as well as exponentiation of the form (...**(1/d))**d. Not surprisingly, the results (from your sample data) don't change if I write:
estimate 'slope tau' d*Pmax/(4*tau);
estimate 'slope inflection' d*Pmax*&q/(tau*(&q)**(1/d)*(&q+1)**2);
estimate 'angle of slope inflection' 180/constant('pi')*atan(d*Pmax*&q/(tau*(&q)**(1/d)*(&q+1)**2));
after defining
%let q=(d-1)/(d+1);
@FreelanceReinh
I was sure this could be further simplified but hadn't found the time yet as it worked and other things seemed to be of greater importance. Nevertheless many thanks for your cleanup! 🙂
Kudos for a very well done question (subject line, source data, code example).
This could actually be used as a positive example.
Just one hint: when using DATALINES, avoid empty lines in the datalines block, and have the terminating semicolon at the start of the line.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: