BookmarkSubscribeRSS Feed
telescopic
Calcite | Level 5

Hi, I have problem on 'exp' function. Please see the bolded line in code.

    a = exp( (-lamda*Y)**gamma )    ;     

where gamma and lamda is (1x1) matrix or scalar. Without "exp", The routine return the value f. But, adding  'exp', it returns error!

Error message-----------------------------------------------------------------

ERROR: (execution) Invalid argument to function.

operation : EXP at line 925 column 12

operands  : _TEM1004

_TEM1004      1 row       1 col     (numeric)

    194481

statement : ASSIGN at line 925 column 5

traceback : module LOGLIK at line 925 column 5

---------------------------------------------------------------------------

I cannot see the reason. Maybe it is due to issue on applying function  elementwise versus on a matrix?

Thank you

Elvin

CODE:

---------------------------------------------------------------------

Data radiotherapy;

   input y age gender $ censor_ind;

datalines;

7 68 f 1

9 69 f 1

12 68 f    1

12 71 f    1

19 77 m    1

23 70 f    1

;

RUN;

PROC IML;

RESET LOG PRINT;

USE radiotherapy VAR _ALL_;

READ all VAR{y} INTO Y;

READ all VAR{age} INTO AGE;

READ all VAR{gender} INTO GENDER;

READ all VAR{censor_ind} INTO CENSOR_IND;

CLOSE radiotherapy;

start LogLik(param) global (Y);

   lamda = param[1];

   gamma = param[2];

   n = nrow(Y);

   f=0;

    DO i=1 to nrow(Y);

    a = exp( (-lamda*Y)**gamma )    ;      

    f=f+a;

    END;

    return ( f );

finish;

p={3 4, 6 9};

ans=LogLik(p);

quit;

3 REPLIES 3
telescopic
Calcite | Level 5

Woops, I think the issue is that the values in my vector 'p' are too small. :smileysilly:

By the way, in IML, can we assign a value as scalar  instead to a (1x1) matrix?

Thank you

Elvin

TomTom
Calcite | Level 5

telescopic wrote:

 

By the way, in IML, can we assign a value as scalar  instead to a (1x1) matrix?


1x1 matrices are scalars

http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_languagechap_s...

The main problem with your programme above is that in your likelihood module the result of the calculation of EXP(194481) is too big for the computer to handle. I think you also want to pass rows of p as arguments to LogLik and not the whole matrix. I suppose you have seen Rick's recent blog post. If not, have a look at what he did:

http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml/

Rick_SAS
SAS Super FREQ

By the way, you don't need the loop over all elements of Y.

start LogLik(param) global (Y);

   lamda = param[1];

   gamma = param[2];

   f = sum( exp((-lamda*Y)##gamma) );

   return ( f );

finish;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 3222 views
  • 0 likes
  • 3 in conversation