stan-dev / stan-dev/posterior

Improve support (or documentation) for weighted draws

Open
#184 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
R
Stars
171
Forks
26
Avg merge
2d 18h
Merged PRs (30d)
3

Description

?weight_draws says Add weights to draws objects, with one weight per draw, for use in subsequent weighting operations. Currently the only supported subsequent operation is resample_draws(), but the documentation doesn't make it clear. Ideally rvars support would be extended to support weighted draws, but if that is infeasible, the documentation should be clarified.

Example:

> x = rvar_rng(rnorm, 4, mean = 1:4, sd = 2)
> w=runif(4000)

weight_draws() is not defined for draws_rvars:

> xw = weight_draws(x, w, log=FALSE)
Error in UseMethod("weight_draws") : 
  no applicable method for 'weight_draws' applied to an object of class "c('rvar', 'vctrs_vctr', 'list')"

There is no error if weighted draws_df is converted to draws_rvars:

> xw = as_draws_rvars(weight_draws(as_draws_df(x), w, log=FALSE))

The default print method gives the unweighted result

> xw
# A draws_rvars: 4000 iterations, 1 chains, and 1 variables
$x: rvar<4000>[4] mean ± sd:
[1] 0.96 ± 2  1.95 ± 2  3.02 ± 2  4.05 ± 2 

and mean fails

> mean(xw)
[1] NA
Warning message:
In mean.default(xw) : argument is not numeric or logical: returning NA

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the weight_draws(), resample_draws(), and as_draws_rvars() entry points, then inspect how draws_rvars objects handle weighted draws and summary operations. Done means either weighted draws_rvars support works, including mean(), or the documentation clearly states the supported limitation and conversion path.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.