我正完全关注此处的博客文章(https://mattocci27.github.io/assets/poilog_mix/poilog_mix.html),但始终遇到一个奇怪的错误。确切地说,我正在运行:
library(rstan)
mu <- c(log(50), log(400))
sigma <- c(0.8, 0.2)
theta <- 0.8
N <- 100
z <- rbinom(N, 1, 1 - theta) + 1
log_lambda <- rnorm(N, mu[z], sigma[z])
Y <- rpois(N, exp(log_lambda))
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
list_dat <- list(N = N, y = Y)
fit_cp <- stan(file = "poilog_mix_cp.stan",
data = list_dat,
iter = 2000,
warmup = 1000,
thin = 1,
chains = 4,
refresh = 500,
control = list(adapt_delta = 0.9, max_treedepth = 20))
具有文件“ poilog_mix_cp.stan”,如下所示:
data{
int<lower=0> N;
int y[N];
}
parameters {
ordered[2] mu;
real<lower=0> sigma[2];
real<lower=0, upper=1> theta;
vector[N] log_lambda[2];
}
model {
sigma ~ cauchy(0, 2.5);
mu ~ normal(0, 10);
theta ~ beta(2, 2);
for (i in 1:2)
log_lambda[i,] ~ normal(mu[i], sigma[i]);
for (n in 1:N)
target += log_mix(theta,
poisson_log_lpmf(y[n] | log_lambda[1, n]),
poisson_log_lpmf(y[n] | log_lambda[2, n]));
}
但是在拟合模型的步骤中,出现以下错误:
Error in as.character(sys.call(sys.parent())[[1L]]) :
cannot coerce type 'closure' to vector of type 'character'
我不确定正在发生什么,因为我只是在复制博客文章。