gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:12:57 25 4
gpt4 key购买 nike

有没有办法从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com