Can you use sample weights in pystan or pymc3?

老子叫甜甜 提交于 2019-12-08 01:19:56

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/47464075/can-you-use-sample-weights-in-pystan-or-pymc3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!