您可以在pystan或pymc3中使用样本权重吗? [英] Can you use sample weights in pystan or pymc3?

查看:107
本文介绍了您可以在pystan或pymc3中使用样本权重吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我观察到的数据集具有权重(例如,跟踪多重性),则可以将其提供给pystan或pymc3,类似于函数签名(

If my observed dataset has weights (for example tracking multiplicity) is it possible to provide this either to pystan or pymc3, similar to the function signature (http://mc-stan.org/rstanarm/reference/stan_glm.html) in the rstanarm package:

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)

推荐答案

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

With Stan (in any of its interfaces, including PyStan), you can introduce weights within the model. For example, in a linear regression, that'd be e.g., instead of y[i] ~ normal(mu[i], sigma) you use target += weight[i] * normal_lpdf(y[i] | mu[i], sigma).

如果权重为正,这将为您提供指定的密度.我们倾向于使用生成方法.

This gives you a well specified density if the weights are positive. We tend to prefer generative approaches.

这篇关于您可以在pystan或pymc3中使用样本权重吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆