Learn R Programming

tidybayes (version 3.0.2)

sample_draws: Sample draws from a tidy-format data frame of draws

Description

Given a tidy-format data frame of draws with a column indexing each draw, subsample the data frame to a given size based on a column indexing draws, ensuring that rows in sub-groups of a grouped data frame are sampled from the same draws.

Usage

sample_draws(data, ndraws, draw = ".draw", seed = NULL)

Arguments

data

Data frame to sample from

ndraws

The number of draws to return, or NULL to return all draws.

draw

The name of the column indexing the draws; default ".draw".

seed

A seed to use when subsampling draws (i.e. when ndraws is not NULL).

Author

Matthew Kay

Details

sample_draws() makes it easier to sub-sample a grouped, tidy-format data frame of draws. On a grouped data frame, the naive approach of using filter with the .draw column will give incorrect results as it will select a different sample within each group. sample_draws() ensures the same sample is selected within each group.