Description Usage Arguments Value Examples
Select Simple Randmom Samples and Stratified Random Samples,
select_sample_prop
can be used when sampling with equal probability
across strata or when selecting a simple random sample.
select_sample_str
selects samples when sample size varies across
strata.
1 2 3 4 5 | select_sample_str(sampling_frame, allocation, sample_size = sample_size,
stratum = stratum, is_frac = FALSE, seed = NA, replace = FALSE)
select_sample_prop(sampling_frame, stratum = stratum, frac, seed = NA,
replace = FALSE)
|
sampling_frame |
|
allocation |
|
sample_size |
unquoted column with sample sizes in the allocation data.frame |
stratum |
unquoted column with strata in the allocation and
sampling_frame |
is_frac |
logical value indicating whether the allocation data.frame contains proportions to be sampled within each stratum (TRUE) or sample sizes. |
seed |
integer value used to set the state of the random number generator. |
replace |
logical value indicating whether the sample should be selected with replacement. |
frac |
when sampling with equal probability across strata, frac is a numeric value indicating the fraction of the data to select. |
A data.frame
with the selected sample, it will have the same
columns as the original sampling frame plus a column indicating the sample
size in the stratum of each selected observation.
1 2 3 4 5 6 7 8 9 10 11 12 | # stratified random sampling
library(dplyr)
sampling_frame <- data.frame(id = 1:100,
str = sample(1:5, 100, replace = TRUE),
val = rnorm(100))
# allocation given by column n in allo data.frame
allo <- dplyr::sampling_frame %>%
group_by(str) %>%
summarise(n = 0.4 * n())
select_sample_str(sampling_frame, allo, n, str)
# SRS (simple random sample)
select_sample_prop(sampling_frame, frac = 0.2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.