stratallo
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.7%) to scientific vocabulary
Last synced: 7 months ago
·
JSON representation
·
Repository
Basic Info
- Host: GitHub
- Owner: wwojciech
- Language: R
- Default Branch: main
- Size: 1.28 MB
Statistics
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Created over 4 years ago
· Last pushed 11 months ago
Metadata Files
Readme
Changelog
Citation
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
\def\R{{\mathbb R}}
\def\x{\mathbf x}
\def\n{\mathbf n}
\newcommand{\texteq}{\mathrm}
# Optimum Sample Allocation in Stratified Sampling with `stratallo`
Functions in this package provide solution to classical problem in survey
methodology - an optimum sample allocation in stratified sampling. In this
context, the optimum allocation is in the classical Tschuprow-Neyman's sense and
it satisfies additional lower or upper bounds restrictions imposed on sample
sizes in strata. In particular, it is assumed that the variance of the
stratified $\pi$ estimator is of the following generic form:
$$
V_{st} = \sum_{h=1}^{H} \frac{A_h^2}{n_h} - A_0,
$$
where $H$ denotes total number of strata, $(n_1,\ldots,n_H)$ is the allocation
vector with strata sample sizes, and population parameters
$A_0$, $A_h > 0$, $h = 1,\ldots,H$, do not depend on the $x_h$, $h = 1,\ldots,H$.
A minor modification of the classical optimum sample allocation problem leads
to the minimum cost allocation. This problem lies in the determination of a
vector of strata sample sizes that minimizes total cost of the survey, under
assumed fixed level of the stratified $\pi$ estimator's variance. As in the case
of the classical optimum allocation, the problem of minimum cost allocation can
be complemented by imposing upper bounds on sample sizes in strata.
There are few different algorithms available to use, and one them is based on
a popular sample allocation method that applies Neyman allocation to recursively
reduced set of strata.
Package *stratallo* provides two **user functions**:
* `opt()`
* `optcost()`
that solve sample allocation problems briefly characterized above as well as the
following **helpers functions**:
* `var_st()`
* `var_st_tsi()`
* `asummary()`
* `ran_round()`
* `round_oric()`.
Functions `var_st()` and `var_st_tsi()` compute a value of the variance $V_{st}$.
The `var_st_tsi()` is a simple wrapper of `var_st()` that is dedicated for the
case of *stratified* $\pi$ *estimator* of the population total with *stratified
simple random sampling without replacement* design in use.
Helper `asummary()` creates a `data.frame` object with summary of the allocation.
Functions `ran_round()` and `round_oric()` are the rounding functions that can
be used to round non-integers allocations (see section Rounding, below).
The package comes with three predefined, artificial populations with 10, 507
and 969 strata. These are stored under `pop10_mM`, `pop507` and `pop969`
objects, respectively.
See package's vignette for more details.
## Installation
You can install the released version of *stratallo* package from
[CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("stratallo")
```
## Examples
These are basic examples that show how to use `opt()` and `optcost()` functions
to solve different versions of optimum sample allocation problem for an example
population with 4 strata.
```{r load_package}
library(stratallo)
```
Define example population.
```{r pop}
N <- c(3000, 4000, 5000, 2000) # Strata sizes.
S <- c(48, 79, 76, 16) # Standard deviations of a study variable in strata.
A <- N * S
n <- 190 # Total sample size.
```
Tschuprow-Neyman allocation (no inequality constraints).
```{r opt_Neyman}
xopt <- opt(n = n, A = A)
xopt
sum(xopt) == n
# Variance of the st. estimator that corresponds to the optimum allocation.
var_st_tsi(xopt, N, S)
```
One-sided upper bounds.
```{r opt_M}
M <- c(100, 90, 70, 80) # Upper bounds imposed on the sample sizes in strata.
all(M <= N)
n <= sum(M)
xopt <- opt(n = n, A = A, M = M)
xopt
sum(xopt) == n
all(xopt <= M) # Does not violate upper-bounds constraints.
# Variance of the st. estimator that corresponds to the optimum allocation.
var_st_tsi(xopt, N, S)
```
One-sided lower bounds.
```{r opt_m}
m <- c(50, 120, 1, 2) # Lower bounds imposed on the sample sizes in strata.
n >= sum(m)
xopt <- opt(n = n, A = A, m = m)
xopt
sum(xopt) == n
all(xopt >= m) # Does not violate lower-bounds constraints.
# Variance of the st. estimator that corresponds to the optimum allocation.
var_st_tsi(xopt, N, S)
```
Box constraints.
```{r opt_box}
m <- c(100, 90, 500, 50) # Lower bounds imposed on sample sizes in strata.
M <- c(300, 400, 800, 90) # Upper bounds imposed on sample sizes in strata.
n <- 1284
n >= sum(m) && n <= sum(M)
xopt <- opt(n = n, A = A, m = m, M = M)
xopt
sum(xopt) == n
all(xopt >= m & xopt <= M) # Does not violate any lower or upper bounds constraints.
# Variance of the st. estimator that corresponds to the optimum allocation.
var_st_tsi(xopt, N, S)
```
Minimization of the total cost with `optcost()` function
```{r optcost}
A <- c(3000, 4000, 5000, 2000)
A0 <- 70000
unit_costs <- c(0.5, 0.6, 0.6, 0.3) # c_h, h = 1,...4.
M <- c(100, 90, 70, 80)
V <- 1e6 # Variance constraint.
V >= sum(A^2 / M) - A0
xopt <- optcost(V = V, A = A, A0 = A0, M = M, unit_costs = unit_costs)
xopt
sum(A^2 / xopt) - A0 == V
all(xopt <= M)
```
Rounding.
```{r rounding}
m <- c(100, 90, 500, 50)
M <- c(300, 400, 800, 90)
n <- 1284
# Optimum, non-integer allocation under box constraints.
xopt <- opt(n = n, A = A, m = m, M = M)
xopt
xopt_int <- round_oric(xopt)
xopt_int
```
Owner
- Name: Wojtek
- Login: wwojciech
- Kind: user
- Repositories: 2
- Profile: https://github.com/wwojciech
Citation (CITATION.cff)
cff-version: 1.0.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Wójciak"
given-names: "Wojciech"
orcid: "https://orcid.org/0000-0002-5042-160X"
- family-names: "Wesołowski"
given-names: "Jacek"
orcid: "https://orcid.org/0000-0001-7615-694X"
- family-names: "Wieczorkowski"
given-names: "Robert"
title: "R Package stratallo - source code"
version: 2.2.1
date-released: 2023-06-24
url: "https://github.com/wwojciech/stratallo"
GitHub Events
Total
- Watch event: 1
- Push event: 1
Last Year
- Watch event: 1
- Push event: 1
Committers
Last synced: about 3 years ago
All Time
- Total Commits: 42
- Total Committers: 4
- Avg Commits per committer: 10.5
- Development Distribution Score (DDS): 0.571
Top Committers
| Name | Commits | |
|---|---|---|
| Wojciech Wójciak | 1****h@u****m | 18 |
| Wojtek | w****k@g****m | 15 |
| Wojtek | w****k@c****m | 6 |
| Robert Wieczorkowski | r****r@g****m | 3 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 0
- Total pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: less than a minute
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- wwojciech (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 242 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 6
- Total maintainers: 1
cran.r-project.org: stratallo
Optimum Sample Allocation in Stratified Sampling
- Homepage: https://github.com/wwojciech/stratallo
- Documentation: http://cran.r-project.org/web/packages/stratallo/stratallo.pdf
- License: GPL-2
-
Latest release: 2.2.1
published over 2 years ago
Rankings
Forks count: 28.8%
Dependent packages count: 29.8%
Stargazers count: 35.2%
Dependent repos count: 35.5%
Average: 37.7%
Downloads: 59.0%
Maintainers (1)
Last synced:
7 months ago
Dependencies
DESCRIPTION
cran
- checkmate * imports
- lifecycle * imports
- knitr * suggests
- rmarkdown * suggests
- spelling * suggests
- testthat >= 3.0.0 suggests