Fortunately, it seems that R's
pgamma(q, shape, rate)
matches Ox's
probgamma(ma, r, a)
So your Ox arguments bear no resemblance to the R ones. I think it should be:
#include <oxstd.h>
#include <oxprob.h>
rantgamma(a, b, c)
{
decl p=probgamma(a, b, c);
//println("p=", p);
decl q = quangamma(p*ranu(1,1), a, b);
return q;
}
main()
{
print(rantgamma(1,1,15));
}
The best way to check is not with random numbers but a few fixed points, then
the answers should be the same.
Jurgen
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox 14th OxMetrics user conference 2014
oxoxoxox Washington DC, 20-21 March
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
James Martin Fellow, Institute for New Economic Thinking
at the Oxford Martin School, University of Oxford
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
On 2014-01-23 18:50, Cibele Russo wrote:
> Hello
>
> May I ask you if it is possible to run R functions from Ox? I really like
> programming in Ox and it is really fast when compared to R, but I don't know how
> to solve the problem below.
>
> I am running some simulations in Ox. In a point of this code, I need to
> generate, for example, a (pseudo) random observation with distribution
> gamma(15,1) truncated at 1, which means that my random observation will be in (0,1).
>
> I have written two pieces of code, in R it works well, but in Ox it always
> returns zero, which is not possible for a (truncated) gamma distribution. Maybe
> it is a rounding issue.
>
> Could anyone help me how to solve it?
>
> Thank you in advance!
> Cibele
>
>
> *Code in R:*
> rtgamma<-function(a,b,c){
> p<-pgamma(c,a,b)
> g<-qgamma(p*runif(1,0,1),a,b)
> g;
> }
> rtgamma(1,15,1)
>
> *Code in Ox:*
> #include <oxstd.h>
> #include <oxprob.h>
> rantgamma(const tr, const sh, const sc)
> {
> decl p=probgamma(tr, sh, sc);
> decl q = quangamma(p*ranu(1,1), sh, sc);
> return q;
> }
> main()
> {
> ranseed(1234);
> print(rantgamma(1,15,1));
> }
>
>
>
>
>
>
|