forked from barcaroli/SamplingStrata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
77 lines (64 loc) · 2.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
output: github_document
keep_md: TRUE
---
<!-- README.md is generated from README.Rmd. Please edit README.Rmd file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# SamplingStrata
This package offers an approach for the determination of the best
stratification of a sampling frame, the one that ensures the
minimum sample cost under the condition to satisfy precision
constraints in a multivariate and multidomain case. This
approach is based on the use of the genetic algorithm: each
solution (i.e. a particular partition in strata of the sampling
frame) is considered as an individual in a population; the
fitness of all individuals is evaluated applying the
Bethel-Chromy algorithm to calculate the sampling size
satisfying precision constraints on the target estimates.
Functions in the package allows to:
(a) analyse the obtained results of the optimisation step;
(b) assign the new strata labels to the sampling frame;
(c) select a sample from the new frame accordingly to the best allocation.
Functions for the execution of the genetic algorithm are a modified
version of the functions in the 'genalg' package.
## Installation
You can install SamplingStrata from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("barcaroli/SamplingStrata")
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r, eval=FALSE, echo=TRUE}
library(SamplingStrata)
data(swisserrors)
data(swissstrata)
solution <- optimizeStrata (
errors = swisserrors,
strata = swissstrata,
showPlot = FALSE)
# update sampling strata with new strata labels
newstrata <- updateStrata(swissstrata,
solution,
writeFiles = FALSE)
# update sampling frame with new strata labels
data(swissframe)
framenew <- updateFrame(frame=swissframe,
newstrata=newstrata,
writeFile=FALSE)
samp <- selectSample(framenew,solution$aggr_strata,writeFiles=TRUE)
# evaluate the current solution
eval <- evalSolution(frame = framenew,
outstrata =solution$aggr_strata,
nsampl = 100,
cens = NULL,
writeFiles = FALSE)
eval$coeff_var
swisserrors
```