if / else语句用于在JAGS中定义分发

时间:2017-10-13 12:43:01

标签: if-statement truncation jags

在JAGS中,我想为参数w [i]定义泊松分布,如果另一个参数e [i]大于0,它也会被截断(大于或等于2)。

基本上我希望它代表:

w [i] ~elelse(e [i]> 0,dpois(mu)T(2,),dpois(mu))

我尝试使用step函数,通过调整响应其他人的帖子而发出的代码,该帖子请求类似的内容:Choosing Different Distributions based on if - else condition in WinBugs/JAGS

但这似乎不起作用?

谢谢

1 个答案:

答案 0 :(得分:1)

也许是这样的?

pois1 ~ dpois(mu) T(2,)
pois2 ~ dpois(mu)
for(i in 1:N){
indicator1[i] <- ifelse(e[i] > 0, 1, 0)
indicator2[i] <- ifelse(e[i] <= 0, 1, 0)
w[i] <- (pois1 * indicator1[i]) + (pois2 * indicator2[i])
}

e[i]大于1 w[i]时,pois1的值为w[i]。如果不是pois2pois1 ~ dpois(mu) T(2,) pois2 ~ dpois(mu) for(i in 1:N){ indicator[i] <- ifelse(e[i] > 0, 1, 0) w[i] <- (pois1 * indicator[i]) + (pois2 * (1 - indicator[i])) } 获取值。

编辑:或者,你只能定义一个指标变量,并按照这样做。

var someReturnObject = new ResultObject();

using (var context = new LinqPadDbContext(@"Server=localhost\SQLEXPRESS;Database=StackOverflow;Trusted_Connection=True;"))
{
    var cmd = context.Database.Connection.CreateCommand();
    cmd.CommandText = "[dbo].[GetSomeData]";

    try
    {           
        context.Database.Connection.Open();

        var reader = cmd.ExecuteReader();

        var result1 = ((IObjectContextAdapter)context).ObjectContext.Translate<string>(reader);

        someResultObject.Text1 = result1.First();

        //for each extra result, start here
        reader.NextResult();

        var users = ((IObjectContextAdapter)context).ObjectContext.Translate<User>(reader);

        someResultObject.Users = users.Select(x => x);
        //stop here
    }
    finally
    {
        context.Database.Connection.Close();
    }
}