- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 STAN(rstan 库)中拟合逻辑模型。我的响应变量没有任何缺失值,但是我的协变量之一“HB”是二进制的,并且缺少条目。
因此,目标是在每次迭代时使用伯努利先验(参数为 0.5)来估算二元向量中缺失的条目。
但是,我遇到了问题:
我使用了 section 3.3 of the STAN user guide 中提供的指南.对于下面的模型,解析器在伯努利赋值行(模型 block 中的倒数第二行)给我一个错误,说它需要整数。注意:我还尝试在参数 block 中将 HB_miss 定义为实数并得到相同的错误。
m2 <- '
data {
int<lower=0> N; // total number of observations
int<lower=0,upper=1> y[N]; // setting the dependent variable y as binary
vector[N] X; // independent variable 1
int<lower=0> N_obs;
int<lower=0> N_miss;
int<lower=1, upper=N> ii_obs[N_obs];
int<lower=1, upper=N> ii_miss[N_miss];
vector[N_obs] HB_obs; // independent variable 2 (observed)
}
parameters {
real b_0; // intercept
real b_X; // beta 1,2, ...
real b_HB;
vector[N_miss] HB_miss;
}
transformed parameters {
vector[N] HB;
HB[ii_obs] = HB_obs;
HB[ii_miss] = HB_miss;
}
model {
b_0 ~ normal(0,100);
b_X ~ normal(0,100);
b_HB ~ normal(0,100);
HB_miss ~ bernoulli(0.5); // This is where the parser gives me an error
y ~ bernoulli_logit(b_0 + b_X * X + b_HB * HB); // model
}
关于如何在 STAN 中有效地在 HB_miss 之前分配伯努利有什么想法吗?
最佳答案
由于您提到的原因,不可能在 Stan 程序中将缺失的离散值视为未知数。 Stan 中的所有算法都使用梯度,并且没有为离散的未知数定义导数。
相反,您需要边缘化未知值,当一切都是二进制时,这并不太乏味。本质上,您可以使用 log_mix
function其参数是:
所以,它会是这样的
for (n in 1:N)
target += log_mix(0.5, bernoulli_logit_lpmf(y[n] | b_0 + b_X * X[i] + b_HB),
bernoulli_logit_lpmf(y[n] | b_0 + b_X * X[i]));
更多详细信息,您可以阅读此博客post .
关于r - R STAN 中的 Bernoulli Prior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57498783/
我知道这个问题已经被问过多次,但我已经没有办法让模型正常工作了。火车数据的前50行: > train[1:25] a b c d e f g h i j
我正在 STAN(rstan 库)中拟合逻辑模型。我的响应变量没有任何缺失值,但是我的协变量之一“HB”是二进制的,并且缺少条目。 因此,目标是在每次迭代时使用伯努利先验(参数为 0.5)来估算二元向
我正在尝试通过 R (R2OpenBUGS) 使用 OpenBUGS 将观察“时间”建模为随机变量。如果所有观察时间都可用(没有 NA),则一切正常,但如果我将其中一个时间设置为 NA,则什么也不会发
我有一个包含如下训练数据集的文件: sentence F1 F2 F3 F4 F5 class this is a dog 0 1 0 0 0 1 i li
我想知道为什么scipy的随机变量类stats.bernoulli产生以dtype int32作为样本的ndarrays: > stats.bernoulli.rvs(0.3, size=10)
我是一名优秀的程序员,十分优秀!