【问题标题】:Can you use sample weights in pystan or pymc3?您可以在 pystan 或 pymc3 中使用样本权重吗?
【发布时间】:2018-05-07 22:13:10
【问题描述】:

如果我观察到的数据集具有权重(例如跟踪多重性),是否可以将其提供给 pystan 或 pymc3,类似于 rstanarm 包中的函数签名 (http://mc-stan.org/rstanarm/reference/stan_glm.html):

stan_glm(formula, family = gaussian(), data, weights, subset,
  na.action = NULL, offset = NULL, model = TRUE, x = FALSE, y = TRUE,
  contrasts = NULL, ..., prior = normal(), prior_intercept = normal(),
  prior_aux = exponential(), prior_PD = FALSE, algorithm = c("sampling",
  "optimizing", "meanfield", "fullrank"), adapt_delta = NULL, QR = FALSE,
  sparse = FALSE)

【问题讨论】:

    标签: python pymc3 stan rstan pystan


    【解决方案1】:

    使用 Stan(在其任何接口中,包括 PyStan),您可以在模型中引入权重。例如,在线性回归中,例如,您使用 target += weight[i] * normal_lpdf(y[i] | mu[i], sigma) 而不是 y[i] ~ normal(mu[i], sigma)

    如果权重为正,这将为您提供明确指定的密度。我们倾向于更喜欢生成方法。

    【讨论】:

    • 您好 Bob,非常感谢您抽出宝贵时间提供帮助。你知道我是否可以为分层逻辑回归做到这一点?当我用bernoulli_logit_lpdf 尝试你的答案时,我收到了错误No matches for::bernoulli_logit_lpdf(vector, vector) Function bernoulli_logit_lpdf not found.
    • 错误信息是正确的——它也应该告诉你什么是可用的。 bernoulli_logit_lpdf 需要一个整数或整数数组作为它的第一个参数,而不是一个向量作为它的第一个参数。是的,你可以分层地做到这一点——加权(对数尺度上的乘法)就是这样做的——就像看到很多分数观察一样。如果权重都是非负整数,那么它会简化为许多观察值的普通定义。
    猜你喜欢
    • 2021-01-17
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多