BookmarkSubscribeRSS Feed
cogprof
Calcite | Level 5

Hello,

 

I’m trying to use proc NLIN to fit a model in which two of the parameters in the model statement live in a function that is recursive with respect to an independent variable.  That is, the value that the function takes on IV level N is in part determined by value of that same function on IV level N-1.

 

Is there a standard way to manage this recursive issue within NLIN? Ideally, I’m looking for something analogous to the lag function but that can operate on a newly defined function rather than just on variables in the input dataset. Hope this makes sense. Happy to provide more detail if it will help.

 

Thank you,

Tim

 

4 REPLIES 4
sbxkoenk
SAS Super FREQ

@cogprof wrote:

That is, the value that the function takes on IV level N is in part determined by value of that same function on IV level N-1.

 

Is there a standard way to manage this recursive issue within NLIN?


What do you mean with "IV level"?

 

There is a standard way.

  • Make your recursive function with PROC FCMP.
  • You can subsequently use / call that newly defined function in PROC NLIN !

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
Base SAS Procedures Guide
FCMP Procedure
Creating Functions and Subroutines
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n16ijqsjbv5mdbn1c6w7j6elpky2.htm#n0st...

says:
PROC FCMP enables you to write functions and CALL routines using DATA step syntax. PROC FCMP functions and CALL routines are stored in a data set and can be called from the DATA step, as well as several SAS/STAT, SAS/ETS, or SAS/OR procedures such as the NLIN, MODEL, and NLP procedures. You can create multiple functions and CALL routines in a single FCMP procedure step.

 

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
Base SAS Procedures Guide
FCMP Procedure
Recursion
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1712ebq466zztn1qli0vyf0e4v8.htm

says:
PROC FCMP routines can be recursive.
A recursive function is a function that calls itself, either directly or indirectly.

 

BR,

Koen

sbxkoenk
SAS Super FREQ

@sbxkoenk wrote:
What do you mean with "IV level"?

I think

IV = Independent Variable

, right?

 

Koen

cogprof
Calcite | Level 5

Thank you Koen.  I'll find time soon to look into using FCMP.  I'd like to keep this thread open as I'm sure I will have some questions.

 

For now I have just one question:  If I calculate the value of the recursive function within FCMP, how is NLIN going to calculate the first and second partial derivatives for the parameters within that function? I don't know know how to calculate them so can't enter it manually.  Can it default to computational approximation?  I ask this question now because if NLIN can't handle that then it may not be worth my efforts to explore using FCMP.

Best,

Tim

sbxkoenk
SAS Super FREQ

SAS/STAT® 15.1 User’s Guide
The NLIN Procedure
Details: NLIN Procedure ✦ p.6931

https://support.sas.com/documentation/onlinedoc/stat/151/nlin.pdf

 

Automatic Derivatives
Depending on the optimization method you select, analytical first- and second-order derivatives are computed automatically. Derivatives can still be supplied using the DER.parm syntax. These DER.parm derivatives are not verified by the differentiator. If any needed derivatives are not supplied, they are computed and added to the programming statements. To view the computed derivatives, use the LISTDER or LIST option.

 

BR, Koen

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is ANOVA?

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.

Discussion stats
  • 4 replies
  • 658 views
  • 2 likes
  • 2 in conversation