如何通过AR(1)模型为MCMC修复此Rstan / R代码?

时间:2019-01-13 16:05:45

标签: r mcmc stan

我试图了解我的Rstan代码在做什么错...请注意,数据只是一些模拟数据。

运行ar1_stan_fit时收到以下错误消息:

  

if(nchar(CXX)== 0){时错误:参数长度为零   另外:警告消息:   在system2(file.path(R.home(component =“ bin”),“ R”)中,args = paste(“ CMD config”,:     运行命令''/Library/Frameworks/R.framework/Resources/bin/R'CMD config CXX14 2> / dev / null'的状态为1”

有何评论?

代码:

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

    ar1.stan <- '
    data {
      int<lower=0> N;
      vector[N] y;
    }

    parameters {
      real mu;
      real phi;
      real<lower=0> sigma;
    } 

    model {
    // Priors
      sigma ~ normal(0, 1);
      mu ~ normal(0, 1);
      phi ~ normal(0, 1);

    // Model
      for (n in 2:N)
      y[n] ~ normal(mu + phi * y[n-1], sigma);
    }'


   AR1_1 <- ar_sim(0.3)

   data <- list(N = 200, y = AR1_1)

   ar1_stan_fit <- stan(model_code = ar1.stan, data = data)

0 个答案:

没有答案