Hi all,
I am a new user for Nimble, and am looking to build a custom distribution (Conway-Maxwell Poisson for under dispersed count data). I think I'm close, but when I try to compile the model, I get an error:
"Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
R version: 4.2.3, Nimble version: 0.13.1
library(COMPoissonReg)
library(nimble)
dCOMP <- nimbleFunction(
run = function(x=integer(), lambda=double(0), nu=double(0), log=logical(0, default=0)) {
returnType(double(0))
logProb <- (1 - nu) * (log(lambda) * x - log(factorial(x))) - lambda - log(sum(exp((1-nu)*(log(lambda)*x - log(factorial(x))) - lambda)))
if (log) return(logProb)
else return(exp(logProb))
})
demoCode <- nimbleCode({
for (i in 1:4) {
x[i] ~ dCOMP(2.8,1.1)
}
})
demoModel <- nimbleModel(demoCode, inits = list(x = rcmp(4, 2.8, 1.2)),
check = FALSE, calculate = FALSE)
CdemoModel <- compileNimble(demoModel)
The output from printErrors():
P_1_demoCode_MID_1_nfCode.cpp: In function 'double rcFun_R_GlobalEnv5(int, double, double, bool)':
P_1_demoCode_MID_1_nfCode.cpp:71:107: error: request for member 'sum' in 'exp(((((double)1 - ARG3_nu_) * ((log(ARG2_lambda_) * (double)ARG1_x_) - log(factorial((double)ARG1_x_)))) - ARG2_lambda_))', which is of non-class type 'double'
71 | Interm_3 = (exp((1 - ARG3_nu_) * (log(ARG2_lambda_) * ARG1_x_ - log(factorial(ARG1_x_))) - ARG2_lambda_)).sum();
| ^~~
P_1_demoCode_MID_1_nfCode.cpp: In member function 'virtual void x_L2_UID_4::simulate(const indexedNodeInfo&) const':
P_1_demoCode_MID_1_nfCode.cpp:113:72: error: cannot bind non-const lvalue reference of type 'NimArr<1, int>&' to an rvalue of type 'NimArr<1, int>'
113 | (**model_x)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1] = rcFun_R_GlobalEnv4(1, 2.8, 1.1);
| ^
In file included from C:\Users\stcunnin\AppData\Local\R\win-library\4.2\nimble\include/nimble/RcppNimbleUtils.h:25,
from C:\Users\stcunnin\AppData\Local\R\win-library\4.2\nimble\include/nimble/NamedObjects.h:28,
from C:\Users\stcunnin\AppData\Local\R\win-library\4.2\nimble\include/nimble/EigenTypedefs.h:26,
from P_1_demoCode_MID_1_nfCode.cpp:6:
C:\Users\stcunnin\AppData\Local\R\win-library\4.2\nimble\include/nimble/NimArr.h:276:3: note: after user-defined conversion: 'NimArr<1, T>::NimArr(int) [with T = int]'
276 | NimArr<1, T>(int is1) : NimArrBase<T>() { setSize(is1); }
| ^~~~~~~~~~~~
P_1_demoCode_MID_1_nfCode.cpp:15:58: note: initializing argument 1 of 'NimArr<1, double> rcFun_R_GlobalEnv4(NimArr<1, int>&, double, double)'
15 | NimArr<1, double> rcFun_R_GlobalEnv4 ( NimArr<1, int> & ARG1_n_, double ARG2_lambda_, double ARG3_nu_ ) {
| ~~~~~~~~~~~~~~~~~^~~~~~~
make: *** [C:/PROGRA~1/R/R-42~1.3/etc/x64/Makeconf:260: P_1_demoCode_MID_1_nfCode.o] Error 1
Any guidance would be much appreciated!
All the best,
Stephanie