Closed SwethaLal closed 3 years ago
With a C snippet, you can access any C function, provided you can link to it. By default, pomp gives you access to the R C API, which includes many distribution functions, but not all. In particular, the discrete Gamma distribution is not provided. I do not know whether any add-on packages provide a C interface for this function.
I was not familiar with this distribution, but I read (in the documentation of the ddgamma
function in extraDistr, that this distribution has p.d.f.
f(x) = F(x+1)-F(x),
where F is the c.d.f. of the Gamma distribution.
Is this right? If so, you could simply do
v = pgamma(I+1,k,1/r) - pgamma(I,k,1/r);
This is assuming that k
is the shape parameter and 1/r
is the scale parameter.
Note that this uses the C API for R which provides pgamma
(the c.d.f. of the Gamma distribution) using the shape/scale (not shape/rate) parameterization.
Note also that C does not support named arguments in function calls.
I was trying to use the discrete gamma distribution in an rprocess step and it showed me the error:
It looks like gamma distribution is defined and can be used here, whereas discrete gamma distribution is not to be found.
The R code I wrote contained the following. mu is the mean and var is the variance of the discrete gamma distribution and k and r gives the shape and rate respectively for the corresponding mu and var values. mu and var are parameters in the code. I've also used library(extraDistr) for enabling the use of the discrete gamma distribution commands.
This gave the error mentioned above. Can we somehow add or call or install the discrete gamma distribution to pomp such that it can be used inside the Csnippets? It works fine otherwise in R, but I was wondering if it could somehow be included for usage inside Csnippets.
Thank you!:)
My R-studio version and system version is as below.