sb_sample: Random sample from splinebins distribution

Description Usage Arguments Details Value Author(s) References Examples

View source: R/sb_sample.R

Description

Draw a random sample of points from a smoothed distribution obtained using splinebins.

Usage

1
sb_sample(splinebinFit, n = 1)

Arguments

splinebinFit

A list as returned by splinebins.

n

A positive integer giving the sample size.

Details

The approximate inverse of the CDF calculated by splinebins is used to generate random values of the smoothed distribution.

Value

A vector of random deviates. Returns NA if an inaccurate fit is detected, as indicated by fitWarn.

Author(s)

David J. Hunter and McKalie Drown

References

Paul T. von Hippel, David J. Hunter, McKalie Drown. Better Estimates from Binned Income Data: Interpolated CDFs and Mean-Matching, Sociological Science, November 15, 2017. https://www.sociologicalscience.com/articles-v4-26-641/

Examples

1
2
3
4
5
6
7
8
# 2005 ACS data from Cook County, Illinois
binedges <- c(10000,15000,20000,25000,30000,35000,40000,45000,
              50000,60000,75000,100000,125000,150000,200000,NA)
bincounts <- c(157532,97369,102673,100888,90835,94191,87688,90481,
               79816,153581,195430,240948,155139,94527,92166,103217)
splinefit <- splinebins(binedges, bincounts, 76091)
sb_sample(splinefit, 5)
hist(sb_sample(splinefit, 3000))

Example output

[1]  84070.661  80241.377  28235.915 128791.205   1783.507

binsmooth documentation built on March 26, 2020, 7:17 p.m.