-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
172 lines (130 loc) · 5.17 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
output: github_document
bibliography: inst/Reference.bib
nocite: |
@Ozturk2021
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures",
out.width = "100%"
)
```
# RankedSetSampling
```{r, echo = FALSE}
description <- read.dcf("DESCRIPTION")
version <- as.vector(description[, "Version"])
min.r <- substr(description[, "Depends"], 7, 11)
```
<!-- badges: start -->
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip)
[![Codecov test coverage](https://codecov.io/gh/biometryhub/RankedSetSampling/branch/main/graph/badge.svg)](https://codecov.io/gh/biometryhub/RankedSetSampling?branch=main)
[![R build status](https://github.com/biometryhub/RankedSetSampling/workflows/R-CMD-check/badge.svg)](https://github.com/biometryhub/RankedSetSampling/actions)
![pkgdown](https://github.com/biometryhub/RankedSetSampling/workflows/pkgdown/badge.svg)
<br>
[![minimal R version](https://img.shields.io/badge/R%3E%3D-`r min.r`-6666ff.svg)](https://cran.r-project.org/)
[![packageversion](https://img.shields.io/badge/Package%20version-`r gsub('-', '--', version)`-orange.svg?style=flat-square)](/commits/main)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/main)
[![Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](http://choosealicense.com/licenses/mit/)
<!-- badges: end -->
The RankedSetSampling package provides a way for researchers to easily implement Ranked Set Sampling in practice.
## Table of Contents
<!-- vim-markdown-toc GFM -->
* [Sampling Methods](#sampling-methods)
* [JPS Sampling](#jps-sampling)
* [RSS Sampling](#rss-sampling)
* [Installation](#installation)
* [Examples](#examples)
* [JPS Sample and Estimator](#jps-sample-and-estimator)
* [SBS PPS Sample and Estimator](#sbs-pps-sample-and-estimator)
* [Citing this package](#citing-this-package)
* [Related Reference](#related-reference)
<!-- vim-markdown-toc -->
## Sampling Methods
### JPS Sampling
Sampling is made following the diagram below.
![JPS sampling diagram](man/figures/jps-diagram.drawio.svg)
### RSS Sampling
Sampling is made following the diagram below.
![RSS sampling diagram](man/figures/rss-diagram.drawio.svg)
## Installation
Use the following code to install this package:
```{r eval=F}
if (!require("remotes")) install.packages("remotes")
remotes::install_github("biometryhub/RankedSetSampling", upgrade = FALSE)
```
## Examples
### JPS Sample and Estimator
<details>
<summary>JPS sample and estimator</summary>
``` r
set.seed(112)
population_size <- 600
# the number of samples to be ranked in each set
H <- 3
with_replacement <- FALSE
sigma <- 4
mu <- 10
n_rankers <- 3
# sample size
n <- 30
rhos <- rep(0.75, n_rankers)
taus <- sigma * sqrt(1 / rhos^2 - 1)
population <- qnorm((1:population_size) / (population_size + 1), mu, sigma)
data <- RankedSetSampling::jps_sample(population, n, H, taus, n_rankers, with_replacement)
data <- data[order(data[, 2]), ]
RankedSetSampling::rss_jps_estimate(
data,
set_size = H,
method = "JPS",
confidence = 0.80,
replace = with_replacement,
model_based = FALSE,
pop_size = population_size
)
#> Estimator Estimate Standard Error 80% Confidence intervals
#> 1 UnWeighted 9.570 0.526 8.88,10.26
#> 2 Sd.Weighted 9.595 0.569 8.849,10.341
#> 3 Aggregate Weight 9.542 0.500 8.887,10.198
#> 4 JPS Estimate 9.502 0.650 8.651,10.354
#> 5 SRS estimate 9.793 0.783 8.766,10.821
#> 6 Minimum 9.542 0.500 8.887,10.198
```
</details>
### SBS PPS Sample and Estimator
<details>
<summary>SBS PPS sample and estimator</summary>
``` r
set.seed(112)
# SBS sample size, PPS sample size
sample_sizes <- c(5, 5)
n_population <- 233
k <- 0:(n_population - 1)
x1 <- sample(1:13, n_population, replace = TRUE) / 13
x2 <- sample(1:8, n_population, replace = TRUE) / 8
y <- (x1 + x2) * runif(n = n_population, min = 1, max = 2) + 1
measured_sizes <- y * runif(n = n_population, min = 0, max = 4)
population <- matrix(cbind(k, x1, x2, measured_sizes), ncol = 4)
sample_result <- sbs_pps_sample(population, sample_sizes)
# estimate the population mean and construct a confidence interval
df_sample <- sample_result$sample
sample_id <- df_sample[, 1]
y_sample <- y[sample_id]
sbs_pps_estimates <- sbs_pps_estimate(
population, sample_sizes, y_sample, df_sample,
n_bootstrap = 100, alpha = 0.05
)
print(sbs_pps_estimates)
#> n1 n2 Estimate St.error 95% Confidence intervals
#> 1 5 5 2.849 0.1760682 2.451,3.247
```
</details>
# Citing this package
This package can be cited using `citation("RankedSetSampling")` which generates
```{r echo=F, comment = NA}
citation("RankedSetSampling")
```
# Related Reference