View source: R/get.selection.R
get.selection | R Documentation |
Reconstruct sample selection, e.g. record was drawn or not drawn (delta = 0/1)
in each sampling stage from bootstrap replicates.
get.selection()
needs the cluster
, strata
and hid
/pid
information (if not NULL
)
to correctly reconstruct if a record was drawn in each sampling stage for each bootstrap replicate.
Is only needed if bootstrap replicates are drawn for a survey
with existing bootstrap replicates from a previous period,
see parameter already.selected
in function draw.bootstrap()
.
get.selection(
dat,
b.rep = attr(dat, "b.rep"),
strata = attr(dat, "strata"),
cluster = attr(dat, "cluster"),
hid = attr(dat, "hid"),
pid = attr(dat, "pid")
)
dat |
either data.frame or data.table containing the survey data with rotating panel design. Should contain only survey data from a single time period. |
b.rep |
character specifying the names of the columns in |
strata |
character vector specifying the name(s) of the column in |
cluster |
character vector specifying cluster in the data. |
hid |
character specifying the name of the column in |
pid |
pid column in |
Returns a list of data.tables.
The length of the list equals the number of sampling stages specified.
Each list entry contains a data.table
with variables for sampling stage and/or
hid
/pid
as well as length(attr(dat,"b.rep"))
columns each indicating if
record/cluster was drawn in the respective sampling stage for the i-th boostrap replicate.
library(surveysd)
library(data.table)
setDTthreads(1)
set.seed(1234)
eusilc <- demo.eusilc(n = 3, prettyNames = TRUE)
## draw replicates with stratification
dat_boot <- draw.bootstrap(eusilc[year<2012], REP = 3, weights = "pWeight",
strata = "region", hid = "hid",
period = "year")
## get selection matrix for year 2011
dat_selection <- get.selection(dat_boot[year==2011])
print(dat_selection)
## draw bootstrap replicates for year 2012
## respecting already selected units for year 2011 ~ dat_selection
## in order to mimic rotating panel design
dat_boot_2012 <- draw.bootstrap(eusilc[year==2012], REP = 3, weights = "pWeight",
strata = "region", hid = "hid",
period = "year",
already.selected = dat_selection)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.