Page 1 of 2
Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 10:06 am
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
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 2:34 pm
by TomDoan
It looks like you want Y to be a FRML, not a series. Use FRML Y = ... rather than SET Y = ...
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 4:41 pm
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
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 5:12 pm
by TomDoan
Have you checked your formulas? It looks like it's unbounded above as you push beta to one and sigmagz to zero.
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 5:46 pm
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
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 7:04 pm
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.
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 7:26 pm
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
Re: Maximise a piecewise defined function
Posted: Wed Jul 17, 2013 9:01 pm
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.
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 2:28 pm
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
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 2:38 pm
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.
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 3:42 pm
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
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 3:49 pm
by TomDoan
You have to attach the data as well.
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 3:55 pm
by rbelhach95
Please find the attached data. Thank you
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 4:02 pm
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/....)
Re: Maximise a piecewise defined function
Posted: Thu Jul 18, 2013 4:17 pm
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