Compilation error under Linux (cholesky_factor_corr)

Operating System: Linux (Debian 9.6 stretch)
Interface Version: Rstan
Compiler/Toolkit: gcc (Debian 6.3.0-18+deb9u1)

I am unable to compile certain models containing (I am assuming) choleksky_factor_corr after updating R to version 3.4.4. I get the compilation error and warning:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/Eigen/Core:383:0,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/Eigen/Dense:1,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/core.hpp:14,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /home/conor/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math.hpp:4,
               
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file62785e71843e.cpp 2> file62785e71843e.cpp.err.txt' had status 1 
Error in sink(type = "output") : invalid connection

The full error is in the file Stan-error.txt (1.5 MB)

However, the first instance of error: in the file is:

file5bdd69427f8f.cpp:384:30: error: ‘class stan::io::reader<stan::math::var>’ has no member named ‘cholesky_factor_corr_constrain’; did you mean ‘cholesky_factor_constrain’?

Does anyone have any ideas?

The contents of my Makevars file is:

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=g++ 
CXX14STD = -std=c++14

My session info is:

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] dplyr_0.7.6        plyr_1.8.4         MASS_7.3-49        rethinking_1.59    glmmTMB_0.2.1.0   
 [6] lme4_1.1-21        Matrix_1.2-12      brms_2.3.1         Rcpp_1.0.1         rstan_2.18.9      
[11] StanHeaders_2.18.1 ggplot2_3.1.1     

loaded via a namespace (and not attached):
 [1] Brobdingnag_1.2-5      splines_3.4.4          gtools_3.5.0           threejs_0.3.1         
 [5] shiny_1.3.1            assertthat_0.2.1       stats4_3.4.4           backports_1.1.4       
 [9] pillar_1.3.1           lattice_0.20-35        glue_1.3.0             digest_0.6.18         
[13] promises_1.0.1         minqa_1.2.4            colorspace_1.3-2       PigSustainR_0.0.0.9000
[17] htmltools_0.3.6        httpuv_1.5.1           dygraphs_1.1.1.4       pkgconfig_2.0.2       
[21] purrr_0.2.5            xtable_1.8-3           mvtnorm_1.0-8          scales_1.0.0          
[25] processx_3.1.0         later_0.8.0            tibble_2.1.1           bayesplot_1.5.0       
[29] DT_0.4                 shinyjs_1.0            withr_2.1.2            TMB_1.7.13            
[33] lazyeval_0.2.2         cli_1.1.0              magrittr_1.5           crayon_1.3.4          
[37] mime_0.6               nlme_3.1-131.1         xts_0.10-2             pkgbuild_1.0.3        
[41] colourpicker_1.0       rsconnect_0.8.8        tools_3.4.4            loo_2.1.0             
[45] prettyunits_1.0.2      matrixStats_0.54.0     stringr_1.3.1          munsell_0.5.0         
[49] bindrcpp_0.2.2         callr_2.0.4            compiler_3.4.4         rlang_0.3.4           
[53] nloptr_1.2.1           grid_3.4.4             ggridges_0.5.0         rstudioapi_0.7        
[57] htmlwidgets_1.2        crosstalk_1.0.0        igraph_1.2.1           miniUI_0.1.1.1        
[61] base64enc_0.1-3        boot_1.3-20            gtable_0.3.0           inline_0.3.15         
[65] abind_1.4-5            markdown_0.8           reshape2_1.4.3         R6_2.4.0              
[69] gridExtra_2.3          rstantools_1.5.0       zoo_1.8-2              bridgesampling_0.4-0  
[73] shinythemes_1.1.1      bindr_0.1.1            shinystan_2.5.0        stringi_1.2.3         
[77] tidyselect_0.2.4       coda_0.19-1     

If you use rstan from GitHub, you also need StanHeaders from GitHub.

1 Like

@bgoodri StanHeaders is installed now but the problem persists. I am using rstan version 2_18.9 and StanHeaders version 2_18.1:

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] dplyr_0.7.6        plyr_1.8.4         MASS_7.3-49        rethinking_1.59    glmmTMB_0.2.1.0   
 [6] lme4_1.1-21        Matrix_1.2-12      brms_2.3.1         Rcpp_1.0.1         rstan_2.18.9      
[11] StanHeaders_2.18.1 ggplot2_3.1.1     

loaded via a namespace (and not attached):
 [1] nlme_3.1-131.1       matrixStats_0.54.0   xts_0.10-2           devtools_1.13.6      threejs_0.3.1       
 [6] httr_1.3.1           tools_3.4.4          TMB_1.7.13           backports_1.1.4      R6_2.4.0            
[11] DT_0.4               lazyeval_0.2.2       colorspace_1.3-2     withr_2.1.2          tidyselect_0.2.4    
[16] gridExtra_2.3        prettyunits_1.0.2    processx_3.1.0       Brobdingnag_1.2-5    curl_3.2            
[21] compiler_3.4.4       git2r_0.25.2         cli_1.1.0            shinyjs_1.0          colourpicker_1.0    
[26] scales_1.0.0         dygraphs_1.1.1.4     mvtnorm_1.0-8        ggridges_0.5.0       callr_2.0.4         
[31] stringr_1.3.1        digest_0.6.18        minqa_1.2.4          base64enc_0.1-3      pkgconfig_2.0.2     
[36] htmltools_0.3.6      htmlwidgets_1.2      rlang_0.3.4          rstudioapi_0.7       shiny_1.3.1         
[41] bindr_0.1.1          zoo_1.8-2            crosstalk_1.0.0      gtools_3.5.0         inline_0.3.15       
[46] magrittr_1.5         loo_2.1.0            bayesplot_1.5.0      munsell_0.5.0        abind_1.4-5         
[51] stringi_1.2.3        pkgbuild_1.0.3       grid_3.4.4           promises_1.0.1       crayon_1.3.4        
[56] miniUI_0.1.1.1       lattice_0.20-35      splines_3.4.4        knitr_1.20           pillar_1.3.1        
[61] igraph_1.2.1         boot_1.3-20          markdown_0.8         shinystan_2.5.0      reshape2_1.4.3      
[66] codetools_0.2-15     stats4_3.4.4         rstantools_1.5.0     glue_1.3.0           nloptr_1.2.1        
[71] httpuv_1.5.1         gtable_0.3.0         purrr_0.2.5          assertthat_0.2.1     mime_0.6            
[76] xtable_1.8-3         coda_0.19-1          later_0.8.0          rsconnect_0.8.8      tibble_2.1.1        
[81] shinythemes_1.1.1    memoise_1.1.0        bindrcpp_0.2.2       bridgesampling_0.4-0

@bgoodri It is only particular models that are not compiling. For instance, this hierarchical Bernoulli regression.

  data{
    int<lower=1> N; 							// the total number of rows in the data
    int<lower=1> N_j;							// the total number of individuals
    int<lower=1> j[N];							// id vector for individuals
    vector[N] x_trial_z;						// the trial number variable
    vector[N] x_cond_c;							// binary variable for reversal (1) or not (0)
    vector[N_j] j_pred_z; 						// the diet condition (individual-level predictor)
    int<lower=0, upper=1> y[N];						// the binary y variable
  }

  parameters{
    real alpha; 							// intercept parameter
    vector[3] beta; 							// vector of observation-level regression coefficients
    vector[4] gamma;							// vector of individual-level predictor coefficients
    vector<lower=0>[4] Sigma;						// standard deviations of random effects (RE)
    cholesky_factor_corr[4] L_Rho;					// cholesky factor of the RE correlation matrix
    matrix[4, N_j] Z;							// scaled (unit normal) RE parameters (for efficiency)
  }

  transformed parameters{
    matrix[4,4] Rho;							// RE correlation matrix
    matrix[N_j,4] nu;							// unscaled RE parameters
    nu = (diag_pre_multiply(Sigma, L_Rho) * Z)';			// transform RE parameters from scaled to unscaled
    Rho = L_Rho * L_Rho';						// transform from lower cholesky matrix to correlation matrix
  }

  model{
    vector[N] eta;				// local variable to hold linear predictor

    // prior distributions
    to_vector(Z) ~ normal(0, 1);		// vector of unit normals for the non-centered parameterisation
    alpha ~ normal(0, 10);
    beta ~  normal(0, 1);
    gamma ~ normal(0, 1);
    L_Rho ~ lkj_corr_cholesky(2.0);
    Sigma ~ normal(0, 1);

    // linear predictor
    for(i in 1:N){
      eta[i] = alpha + nu[j[i],1] + gamma[1] * j_pred_z[j[i]]
            + (beta[1] + nu[j[i],2] + gamma[2] * j_pred_z[j[i]]) * x_trial_z[i]
            + (beta[2] + nu[j[i],3] + gamma[3] * j_pred_z[j[i]]) * x_cond_c[i]
            + (beta[3] + nu[j[i],4] + gamma[4] * j_pred_z[j[i]]) * x_trial_z[i] * x_cond_c[i];

    }

     // Bernoulli likelihood statement
      y ~ bernoulli_logit(eta);
  }

@bgoodri I solved it via a clean install of rstan from Cran rather than Github.