Description Usage Arguments Value Examples
Draws samples from a simple population of data and returns (1) the sample index and (2) the sampled values from the population. Useful for generating draws from small, finite populations for pedagogical demonstrations or for generating sampling distributions.
1 | draw_samples(y, n)
|
y |
Vector of population data to generate samples with. The vector can be anything, numeric or otherwise, but is primarily intended for working with numerical data. The length of y will be used as the population size, N. |
n |
Sample size to use when drawing samples. |
sample_indices A matrix with choose(N, n) rows and n columns. Each row corresponds to a sample of the indices in the population, y.
sampled_data A matrix with choose(N, n) rows and n columns. Each row is a sample drawn from y with sample size n.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Example 1:
# ----------
set.seed(1)
y <- rnorm(10)
out <- draw_samples(y, 3)
out$sample_indices[1:3, ]
# [,1] [,2] [,3]
#[1,] 1 2 3
#[2,] 1 2 4
#[3,] 1 2 5
out$sampled_data[1:3, ]
# [,1] [,2] [,3]
#[1,] -0.6264538 0.1836433 -0.8356286
#[2,] -0.6264538 0.1836433 1.5952808
#[3,] -0.6264538 0.1836433 0.3295078
# Example 2:
# ----------
y <- c(1, 3, 3)
out <- draw_samples(y, 2)
out$sample_indices
# [,1] [,2]
#[1,] 1 2
#[2,] 1 3
#[3,] 2 3
out$sampled_data
# [,1] [,2]
#[1,] 1 3
#[2,] 1 3
#[3,] 1 3
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.