samplingin is a robust solution employing SRS (Simple Random Sampling), systematic and PPS (Probability Proportional to Size) sampling methods, ensuring a methodical and representative selection of data. Seamlessly allocate predetermined allocations to smaller levels.
get_allocation()
allocate predetermined allocations to
smaller levels using proportional allocation methoddoSampling()
samples selection using srs, systematic or
PPS (Probability Proportional to Size) sampling method based on certain
allocation.install.packages("samplingin")
library(samplingin)
library(magrittr)
library(dplyr)
= alokasi_dt %>%
contoh_alokasi select(-n_primary) %>%
mutate(nasional = 1)
= get_allocation(
alokasi_dt data = contoh_alokasi
alokasi = 100
, group = c("nasional")
, pop_var = "jml_kabkota"
,
)
# Simple Random Sampling (SRS)
= doSampling(
dtSampling_srs pop = pop_dt
alloc = alokasi_dt
, nsample = "n_primary"
, type = "U"
, ident = c("kdprov")
, method = "srs"
, auxVar = "Total"
, seed = 7892
,
)
# Population data with flag sample
= dtSampling_srs$pop
pop_dt
# Selected Samples
= dtSampling_srs$sampledf
dsampel
# Details of sampling process
= dtSampling_srs$details
rincian
# PPS Sampling
= doSampling(
dtSampling_pps pop = pop_dt
alloc = alokasi_dt
, nsample = "n_primary"
, type = "U"
, ident = c("kdprov")
, method = "pps"
, auxVar = "Total"
, seed = 1234
,
)
# Population data with flag sample
= dtSampling_pps$pop
pop_dt
# Selected Samples
= dtSampling_pps$sampledf
sampledf
# Details of sampling process
= dtSampling_pps$details
details
# Systemtic Sampling
= doSampling(
dtSampling_sys pop = pop_dt
alloc = alokasi_dt
, nsample = "n_primary"
, type = "U"
, ident = c("kdprov")
, method = "systematic"
, seed = 4321
,
)
# Population data with flag sample
= dtSampling_sys$pop
pop_dt
# Selected Samples
= dtSampling_sys$sampledf
sampledf
# Details of sampling process
= dtSampling_sys$details
details
# Systematic Sampling (Secondary Samples)
= alokasi_dt %>%
alokasi_dt_p mutate(n_secondary = 2 * n_primary)
= doSampling(
dtSampling_sys_p pop = dtSampling_sys$pop
alloc = alokasi_dt_p
, nsample = "n_secondary"
, type = "P"
, ident = c("kdprov")
, method = "systematic"
, seed = 6789
, is_secondary = TRUE
,
)
# Population data with flag sample
= dtSampling_sys_p$pop
pop_dt
# Selected Samples
= dtSampling_sys_p$sampledf
dsampel
# Details of sampling process
= dtSampling_sys_p$details
rincian
# Systematic Sampling with predetermined random number (predetermined_rn parameter)
= alokasi_dt %>% rowwise() %>% mutate(ar = runif(n(),0,1)) %>% ungroup
alokasi_dt_rn
= doSampling(
dtSampling_sys pop = pop_dt
alloc = alokasi_dt_rn
, nsample = "n_primary"
, type = "U"
, ident = c("kdprov")
, method = "systematic"
, predetermined_rn = "ar"
, seed = 4321
,
)
# Population data with flag sample
= dtSampling_sys$pop
pop_dt
# Selected Samples
= dtSampling_sys$sampledf
sampledf
# Details of sampling process
= dtSampling_sys$details details