sample_rvtable: Sample A Random Variable Table

Description Usage Arguments Details Value Examples

View source: R/sampling.R

Description

Bootstrap resampling with replacement from a distribution of a random variable stored in an rvtable.

Usage

1
2
sample_rvtable(x, resample = FALSE, n = 10000, interp = TRUE,
  n.interp = 1e+05, decimals = NULL, density.args)

Arguments

x

an rvtable object.

resample

if x is a sample-based rvtable, return x unchanged if resample=FALSE. Otherwise resample from the samples in the Val column. Ignored if rvtable is distribution-based.

n

bootstrap sample size.

interp

linearly interpolate between observed values of Val before sampling if Val is continuous. Ignored for discrete random variables.

n.interp

length of sequence of interpolated sampling points if. Ignored for discrete random variables or interp=FALSE.

decimals

number of decimal places for rounding samples. Ignored for discrete random variables.

density.args

optional arguments passed to density. If supplied, overrides the density.args attribute of x.

Details

Resample an rvtable yielding a new rvtable. This is used to convert from a distribution-based rvtable, which has Val and Prob columns representing a distribution to one with only a Val column representing samples from a distribution. This is often used preceding plotting data in an rvtable so that samples may be passed to plot code rather than a representation of a distribution using values and associated probabilities. This function can also take a sample-based rvtable, in which case it will resample it if resample=TRUE. If is sample-based rvtable is passed and the random variable is continuous, the generation of a new continuous density prior to resampling can be controlled via density.args. All rvtable objects are either distribution-based or sample-based.

Value

an rvtable object where the Val column represents samples and the Prob column is dropped.

Examples

1
2
3
4
5
x <- rvtable(rnorm(1000))
sample_rvtable(x, n=10)
x <- rvtable(sample(1:100, 50), discrete=TRUE)
y <- sample_rvtable(x, n=10)
sample_rvtable(y, n=8, resample=TRUE)

leonawicz/rvtable documentation built on May 21, 2019, 5:09 a.m.