r - 使用 stan 从偏态正态分布中绘制

标签 r normal-distribution stan

有没有办法从 stan 中的偏态正态分布中提取数据?如果不是,有没有办法从正态分布中提取然后转换为偏正态分布?

更新

我在 stan 手册中找到了 y~skew_normal(mu, sigma, alpha),但是当我使用参数对 1000 个值进行采样时

mu=1, 西格玛=10, alpha=-1000

我也得到一些 -inf 值。有什么想法吗?

更新 2

我的testing.stan

data{
  real mu;
  real sigma;
  real alpha;
}
model{

}
generated quantities{
  real temp;

    temp = skew_normal_rng( mu,  sigma,  alpha);

}

然后是我的testing.R文件

sdata <- list(
  mu=1,
  sigma=10,
  alpha=-1000
)

 model <- stan_model("stan code//testing.stan")

system.time(
  samples  <- sampling(model,data=sdata,seed=42,
                       chain=1,algorithm="Fixed_param",
                       iter=10000,thin=1,control=list(max_treedepth=9)
  ) 
)

object <- rstan::extract(samples)
# hist(object$temp,breaks=100)
# plot(density(object$temp))
# mean(is.finite(object$temp))
# sum(!is.finite(object$temp))
sort(object$temp)

在运行 sort(object$temp) 之后,我得到了一些 -inf 值。

最佳答案

运行这个模型:

参数 { 真实的你; } 模型 { y ~ skew_normal(1, 10, -1000); }

我没有得到无限抽奖。不过,我确实得到了很多分歧,这意味着数字不稳定。即使我降低初始步长并提高目标接受率也是如此。

使用 -10 而不是 -1000 的偏斜参数,该问题就消失了。

可能有一些方法可以更改内部实现以提高极端偏斜值的稳定性,但它在 -1000 的数值上肯定存在问题。

关于r - 使用 stan 从偏态正态分布中绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43496065/

相关文章:

python - 在 Python 中缩放正态分布

r - 从R中的 "rstanarm"包获取标准化系数?

R - 分别在 3d 中绘制两个二元法线及其轮廓

r - 无法在 Ubuntu 18.04 LTS 上安装 rstanarm

r - 在不运行单独模型的情况下从先前采样

r - 如何在不破坏 data.table 的自定义评估的情况下调整 `[.data.table` 中的 j?

R:xlsx (0.4.2) 包的 rJava 错误

r - 从分位数回归/摘要中提取 R^2()

r - ggplot2 geom_segment() 中箭头的外观

python - 如何生成平均值为 11.7 的随机正态分布(在 Python 中)