Maximise a piecewise defined function

Econometrics questions and discussions
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Maximise a piecewise defined function

Unread post by rbelhach95 »

Dear Tom,
Hope all is well. I have this a little problem with my attached code, I need to maximize a piecewise defined function, I use the SET command with the %if condition but I get an error there, your help is greatly appreciated.
Rachid
Attachments
Code_Maximize.PRG
(761 Bytes) Downloaded 1047 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

It looks like you want Y to be a FRML, not a series. Use FRML Y = ... rather than SET Y = ...
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Thanks Tom, very much appreciated. The code works fine now but every time I run it, RATS crashes and the program stops working, I guess because of my initial values, I have tried many other possible values but to no avail. Thank you for any additional advice
Rachid
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

Have you checked your formulas? It looks like it's unbounded above as you push beta to one and sigmagz to zero.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Dear Tom,

Thanks for the great help, I was about to send you the new formula as I have forgotten to standardize it (please see attached) and I changed a sign, it looks fine now, beta suppose to be in [0,1), alpha is any real number, but the program still stops running, please advise Thank you
Rachid
Attachments
Code_Maximize_2.txt
(797 Bytes) Downloaded 1108 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

In

s11=(2/sigmagz)*%density((z(t)-mugz)/sigmagz*(1-beta))

is the 1-beta supposed to be in the numerator or denominator? As written, it will be numerator.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Thanks Tom, yes you are right, it's supposed to be in the denominator, I have fixed it but still unable to run.
Best
Rachid
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

This isn't going to do what you want:

set z = mugz+sigmagz*x(t)

Since it's not a FRML, it will have no effect when mugz and sigmagz are changed, and, in fact, will just define z to be all NA's given where it's positioned. I'm not even sure what the point is---even if it's a FRML, all is does is reverse out the mugz and sigmagz effect on x.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Dear Tom,

Thanks a lot for your comments. standardizing the distribution makes it more flexible, location scale family distribution.Could you please tell me how to make it into a FRML and where to put it so that it works, I tried several options but I don't know where the t should be either. Please advise
Rachid
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

It would be FRML Z rather that SET Z, but it you're trying to standardize, wouldn't you want

frml z = (x(t)-mugz)/sigmagz

rather than

frml z = mugz+sigmagz*x(t)

and wouldn't you want to replace (x(t)-mugz)/sigmagz throughout your formulas with z(t). Between your first and second revisions, you defined the Z, but then plugged it in 1 for 1 for X, which will be very different.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Dear Tom,
Many thanks for your continuous support. I just checked out the paper where I found this skew split normal, they mixed up the the standard notation, x is their z in fact, but I ignored the z and wrote the distribution in terms of x, and used their initial values but I know get an error in the log(s11*s12) and I have no clue what the source of the error is, I have run similar distributions with four parameters and they work fine except for this one. Please see attached edited code. Your help is appreciated
Attachments
Code_Maximize.PRG
(787 Bytes) Downloaded 1034 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

You have to attach the data as well.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Please find the attached data. Thank you
Attachments
Drums.txt
(6.97 KiB) Downloaded 1066 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Maximise a piecewise defined function

Unread post by TomDoan »

There's nothing in the log likelihood that constrains beta to be on [0,1] and apparently negative values permit rather high likelihoods. In order to enforce non-negativity you need:

nonlin mugz sigmagz alpha beta beta>=0.0

and you're missing closing )'s in several of the calculations where you added the (1/....)
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Maximise a piecewise defined function

Unread post by rbelhach95 »

Dear Tom,

Many thanks for your reply. I have rearranged the terms little bit to make the code more readable, see attached, but this time with the additional constraint it gives "RATS exe.32 stopped working". I don't know why this is happening. Please advise. Thank you
Rachid
Attachments
Code_Maximize.PRG
(799 Bytes) Downloaded 1038 times
Post Reply