Hi,
I’m trying to compile the CMP.stan program but I get
Compilation ERROR, function(s)/method(s) not created! In file included from /home/max/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/Core:392:0,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/Dense:1,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/rev/core.hpp:14,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /home/max/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math.hpp:4,
from /home/max
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command '/usr/local/lib/R/bin/R CMD SHLIB file11bc3c992a93.cpp 2> file11bc3c992a93.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection
My Stan installation is otherwise fine (can compile many other models). I’ve tried many of the solutions in this forum to problems similar to the one I report, with no success.
Session info:
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
locale:
[1] LC_CTYPE=pt_BR.UTF-8 LC_NUMERIC=C LC_TIME=pt_BR.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=pt_BR.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=pt_BR.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstan_2.18.2 StanHeaders_2.18.0-1 ggplot2_3.1.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 pillar_1.3.1 compiler_3.5.1 plyr_1.8.4 bindr_0.1.1 prettyunits_1.0.2 tools_3.5.1
[8] pkgbuild_1.0.2 tibble_1.4.2 gtable_0.2.0 pkgconfig_2.0.2 rlang_0.3.0.1 cli_1.0.1 rstudioapi_0.8
[15] parallel_3.5.1 yaml_2.2.0 loo_2.0.0 bindrcpp_0.2.2 gridExtra_2.3 withr_2.1.2 dplyr_0.7.8
[22] stats4_3.5.1 grid_3.5.1 tidyselect_0.2.5 inline_0.3.15 glue_1.3.0 R6_2.3.0 processx_3.2.1
[29] callr_3.1.0 purrr_0.2.5 magrittr_1.5 matrixStats_0.54.0 scales_1.0.0 ps_1.2.1 assertthat_0.2.0
[36] colorspace_1.3-2 lazyeval_0.2.1 munsell_0.5.0 crayon_1.3.4
Here’s the code in the link:
// see https://arxiv.org/abs/1612.06618
functions {
real log_C(real log_lambda, real nu) {
real log_C = log1p_exp(log_lambda);
real lfac = 0;
real term = 0;
real k = 2;
if (nu < 0) reject("nu must be non-negative");
if (nu == 0) {
if (log_lambda >= 0) reject("log_lambda must be < 0");
return -log1m_exp(log_lambda);
}
if (nu == 1) return exp(log_lambda);
if (nu == positive_infinity()) return log_C;
while (term > -745) { // exp(-745) underflows
lfac += log(k);
term = k * log_lambda - nu * lfac;
log_C = log_sum_exp(log_C, term);
k += 1;
}
return log_C;
}
real CMP_lpmf(int y, real lambda, real nu) {
if (nu == 0) return y * log(lambda) + log1m(lambda);
if (nu == 1) return poisson_lpmf(y | lambda);
if (nu == positive_infinity())
return bernoulli_lpmf(y | lambda / (1 + lambda));
{
real log_lambda = log(lambda);
return y * log_lambda - nu * lgamma(y + 1) - log_C(log_lambda, nu);
}
}
real CMP_log_lpmf(int y, real log_lambda, real nu) {
if (nu == 0) return y * log_lambda + log1m_exp(log_lambda);
if (nu == 1) return poisson_log_lpmf(y | log_lambda);
if (nu == positive_infinity()) return bernoulli_logit_lpmf(y | log_lambda);
return y * log_lambda - nu * lgamma(y + 1) - log_C(log_lambda, nu);
}
int CMP_log_rng(real log_lambda, real nu) {
int y = 0;
real log_c = log_C(log_lambda, nu);
real u = uniform_rng(0,1);
real CDF = exp(-log_c);
real lfac = 0;
if (CDF >= u) return 0;
while (CDF < u) {
y += 1;
lfac += log(y);
CDF += exp(y * log_lambda - nu * lfac - log_c);
}
return y - 1;
}
int CMP_rng(real lambda, real nu) {
return CMP_log_rng(log(lambda), nu);
}
}
data {
int<lower=1> N;
int<lower=0> y[N];
}
transformed data {
real sum_y = sum(y);
real sum_lfac = 0;
for (n in 1:N) sum_lfac += lgamma(y[n] + 1);
}
parameters {
real<lower=0> nu;
real<lower=0, upper=(nu == 0 ? 1 : positive_infinity())> lambda;
}
model {
real log_lambda = log(lambda);
target += sum_y * log_lambda - nu * sum_lfac - N * log_C(log_lambda, nu);
// priors
}
Thanks in advance,
Luiz