1

我按照https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started的说明构建了 rtools 3.4 和 rstan 2.17.3 。

我在下面保存了文件“8schools.stan”:

data {
  int<lower=0> J; // number of schools 
  real y[J]; // estimated treatment effects
  real<lower=0> sigma[J]; // s.e. of effect estimates 
}
parameters {
  real mu; 
  real<lower=0> tau;
  real eta[J];
}
transformed parameters {
  real theta[J];
  for (j in 1:J)
    theta[j] = mu + tau * eta[j];
}
model {
  target += normal_lpdf(eta | 0, 1);
  target += normal_lpdf(y | theta, sigma);
}

但是当我调用代码时:

library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
fit <- stan(file = '8schools.stan', data = schools_dat, 
            iter = 3, chains = 4)

我收到此错误:

hash mismatch so recompiling; make sure Stan code ends with a blank line
In file included from C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/config.hpp:39:0,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file1b0858a92ea1.cpp:8:
C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
Error in checkForRemoteErrors(val) : 
  4 nodes produced errors; first error: unable to load shared object 'C:/Users/ubashir/AppData/Local/Temp/RtmpgJlrXy/file163456d0a16.dll':
  LoadLibrary failure:  Access is denied.

请协助!

=================== 更新=============================== ================

所以我在 Rtools 3.5 和 rstan 之后重新安装了 R 版本 3.5.1(通过 install.packages())

现在 rstan 因多核支持而失败,如下所示:

library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = 8)
fit <- stan(file = '8schools.stan', data = schools_dat, 
            iter = 3, chains = 4)

有错误:

Loading required namespace: rstudioapi
Error in checkForRemoteErrors(val) : 
  4 nodes produced errors; first error: unable to load shared object 'C:/Users/ubashir/AppData/Local/Temp/RtmpAtefGs/file241c40952587.dll':
  LoadLibrary failure:  Access is denied.

但是,如果我将线路更改为单核,我可以让代码至少工作

4

1 回答 1

0

只需在“8schools.stan”的末尾添加一个换行符

于 2018-04-24T13:10:47.973 回答