R: Updates the initial frame on the basis of the optimized...
updateFrame
R Documentation
Updates the initial frame on the basis of the optimized stratification
Description
Once optimal stratification has been obtained, and new labels have been attributed to initial
atomic strata ("newstrata"), it is important to report the new classification of units in the
sampling frame by attributing new strata labels to each unit.
By executing this function, a new frame will be obtained with the same structure of the old,
but with the addition of a new stratum label.
The initial frame must contain a variable named 'domainvalue' that indicates the
same values of the domain that has been used with the 'optimizeStrata' function.
If no domains have been defined, this variable will contains all 1's, but it must exist
Usage
updateFrame(frame, newstrata, writeFiles = FALSE)
Arguments
frame
This is the (mandatory) dataframe containing the sampling frame.
newstrata
This is the (mandatory) dataframe containing the information related to the optimisation applied to
initial stratification (new labels applied to atomic strata). It is produced by executing
the "updateStrata" function.
writeFiles
Flag to write or not the new sampling frame into the working directory.
Default is "FALSE"
Value
A dataframe containing the frame
Author(s)
Giulio Barcaroli
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, writeFiles = TRUE)
# updating sampling frame with new strata labels
data(swissframe)
framenew <- updateFrame(frame=swissframe, newstrata=newstrata, writeFiles = TRUE)
## 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/updateFrame.Rd_%03d_medium.png", width=480, height=480)
> ### Name: updateFrame
> ### Title: Updates the initial frame on the basis of the optimized
> ### stratification
> ### Aliases: updateFrame
> ### 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, writeFiles = TRUE)
> ##D # updating sampling frame with new strata labels
> ##D data(swissframe)
> ##D framenew <- updateFrame(frame=swissframe, newstrata=newstrata, writeFiles = TRUE)
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>