Last data update: 2014.03.03

R: Selection of a stratified sample from the frame with srswor...
selectSampleR Documentation

Selection of a stratified sample from the frame with srswor method

Description

Once optimal stratification has been obtained (in the dataframe 'outstrata'), and a new frame has been built by assigning to the units of the old one the new stratum labels (by means of "updateFrame" function), it is possible to select a stratified sample from the frame with the srswor method. The result of the execution of "selectSample" function is a dataframe containing selected units, with the probabilities of inclusion. It is possible to output this dataframe in a .csv file. One more .csv file is produced ("sampling check"), containing coeherence checks between (a) population in frame strata (b) population in optimised strata (c) planned units to be selected in optimised strata (d) actually selected units (e) sum of weights in each stratum

Usage

selectSample(frame, outstrata, writeFiles = FALSE,verbatim=TRUE)

Arguments

frame

This is the (mandatory) dataframe containing the sampling frame, as it has been modified by the execution of the "updateFrame" function. Name of stratum variable must be 'strato'.

outstrata

This is the (mandatory) dataframe containing the information related to resulting stratification obtained by the execution of "optimizeStrata" function. Name of stratum variable must be 'strato'.

writeFiles

Indicates if at the end of the processing the resulting strata will be outputted in a delimited file. Default is "FALSE".

verbatim

Indicates if information on the drawn sample must be printed or not. Default is "TRUE".

Value

A dataframe containing the sample

Author(s)

Giulio Barcaroli with contribution from Diego Zardetto

Examples

#
# The following example is realistic, but is time consuming
#
## Not run: 
library(SamplingStrata)
data(swisserrors)
data(swissstrata)
# optimisation of sampling strata
solution <- optimizeStrata ( 
    errors = swisserrors, 
    strata = swissstrata, 
    cens = NULL,
    strcens = FALSE,
    initialStrata = 3000,
    addStrataFactor = 0.01,    
    minnumstr = 2,
    iter = 60,
    pops = 20,
    mut_chance = 0.05,
    elitism_rate = 0.2,
    highvalue = 100000000,
    suggestions = NULL,
	writeFiles = FALSE)
# updating sampling strata with new strata labels
newstrata <- updateStrata(swissstrata, solution)
# updating sampling frame with new strata labels
data(swissframe)
framenew <- updateFrame(frame=swissframe,newstrata=newstrata)
# selection of sample
sample <- selectSample(frame=framenew,outstrata=solution$aggr_strata)
head(sample)

## End(Not run)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SamplingStrata)
Loading required package: memoise
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SamplingStrata/selectSample.Rd_%03d_medium.png", width=480, height=480)
> ### Name: selectSample
> ### Title: Selection of a stratified sample from the frame with srswor
> ###   method
> ### Aliases: selectSample
> ### Keywords: survey
> 
> ### ** Examples
> 
> #
> # The following example is realistic, but is time consuming
> #
> ## Not run: 
> ##D library(SamplingStrata)
> ##D data(swisserrors)
> ##D data(swissstrata)
> ##D # optimisation of sampling strata
> ##D solution <- optimizeStrata ( 
> ##D     errors = swisserrors, 
> ##D     strata = swissstrata, 
> ##D     cens = NULL,
> ##D     strcens = FALSE,
> ##D     initialStrata = 3000,
> ##D     addStrataFactor = 0.01,    
> ##D     minnumstr = 2,
> ##D     iter = 60,
> ##D     pops = 20,
> ##D     mut_chance = 0.05,
> ##D     elitism_rate = 0.2,
> ##D     highvalue = 100000000,
> ##D     suggestions = NULL,
> ##D 	writeFiles = FALSE)
> ##D # updating sampling strata with new strata labels
> ##D newstrata <- updateStrata(swissstrata, solution)
> ##D # updating sampling frame with new strata labels
> ##D data(swissframe)
> ##D framenew <- updateFrame(frame=swissframe,newstrata=newstrata)
> ##D # selection of sample
> ##D sample <- selectSample(frame=framenew,outstrata=solution$aggr_strata)
> ##D head(sample)
> ## End(Not run)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>