From f3f0542fb9bddeea7bc7ba8a567ed968cb557229 Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Fri, 14 Feb 2025 11:04:05 +1030 Subject: [PATCH 1/3] test indent --- README.Rmd | 78 ++++++++++++++++++++++++------------------------- README.md | 86 ++++++++++++++++++++++++++---------------------------- 2 files changed, 80 insertions(+), 84 deletions(-) diff --git a/README.Rmd b/README.Rmd index b5f48da..b27a4c2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -84,45 +84,45 @@ remotes::install_github("AAGI-AUS/InPlotSampling", upgrade = FALSE) ### JPS Sample and Estimator
- JPS sample and estimator - - ``` 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 <- InPlotSampling::jps_sample(population, n, H, taus, n_rankers, with_replacement) - data <- data[order(data[, 2]), ] - - InPlotSampling::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 - ``` +JPS sample and estimator + +``` 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 <- InPlotSampling::jps_sample(population, n, H, taus, n_rankers, with_replacement) +data <- data[order(data[, 2]), ] + +InPlotSampling::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 +```
### SBS PPS Sample and Estimator diff --git a/README.md b/README.md index b82dc9b..67fd670 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus [![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/InPlotSampling/workflows/R-CMD-check/badge.svg)](https://github.com/biometryhub/InPlotSampling/actions) -![pkgdown](https://github.com/biometryhub/InPlotSampling/workflows/pkgdown/badge.svg) +status](https://github.com/AAGI-AUS/InPlotSampling/workflows/R-CMD-check/badge.svg)](https://github.com/AAGI-AUS/InPlotSampling/actions) +![pkgdown](https://github.com/AAGI-AUS/InPlotSampling/workflows/pkgdown/badge.svg)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r-project.org/) [![packageversion](https://img.shields.io/badge/Package%20version-0.1.0-orange.svg?style=flat-square)](/commits/main) -[![Last-changedate](https://img.shields.io/badge/last%20change-2025--02--11-yellowgreen.svg)](/commits/main) +[![Last-changedate](https://img.shields.io/badge/last%20change-2025--02--14-yellowgreen.svg)](/commits/main) [![Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](http://choosealicense.com/licenses/mit/) @@ -68,7 +68,7 @@ Use the following code to install this package: ``` r if (!require("remotes")) install.packages("remotes") -remotes::install_github("biometryhub/InPlotSampling", upgrade = FALSE) +remotes::install_github("AAGI-AUS/InPlotSampling", upgrade = FALSE) ``` ## Examples @@ -76,48 +76,46 @@ remotes::install_github("biometryhub/InPlotSampling", upgrade = FALSE) ### JPS Sample and Estimator
- - JPS sample and estimator ``` 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 <- InPlotSampling::jps_sample(population, n, H, taus, n_rankers, with_replacement) - data <- data[order(data[, 2]), ] - - InPlotSampling::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 +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 <- InPlotSampling::jps_sample(population, n, H, taus, n_rankers, with_replacement) +data <- data[order(data[, 2]), ] + +InPlotSampling::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 ```
@@ -125,9 +123,7 @@ JPS sample and estimator ### SBS PPS Sample and Estimator
- - SBS PPS sample and estimator @@ -172,7 +168,7 @@ generates Ozturk O, Rogers S, Kravchuk O, Kasprzak P (2021). _InPlotSampling: Easing the Application of Ranked Set Sampling in Practice_. R package - version 0.1.0, . + version 0.1.0, . A BibTeX entry for LaTeX users is @@ -181,7 +177,7 @@ generates author = {Omer Ozturk and Sam Rogers and Olena Kravchuk and Peter Kasprzak}, year = {2021}, note = {R package version 0.1.0}, - url = {https://biometryhub.github.io/InPlotSampling/}, + url = {https://aagi-aus.github.io/InPlotSampling/}, } # Related Reference From c847e098854a528183addfe394807ef2f6a315ab Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Fri, 14 Feb 2025 11:16:19 +1030 Subject: [PATCH 2/3] add more sampling methods --- README.Rmd | 79 +++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/README.Rmd b/README.Rmd index b27a4c2..061ad35 100644 --- a/README.Rmd +++ b/README.Rmd @@ -38,7 +38,14 @@ min.r <- substr(description[, "Depends"], 7, 11) -The InPlotSampling package provides a way for researchers to easily implement Ranked Set Sampling in practice. +The InPlotSampling package provides a way for researchers to easily implement these sampling methods in +practice. + +- Judgment post-stratified (JPS) sampling +- Ranked set sampling (RSS) +- Porbability-proportional to size (PPS) sampling +- Spatially balanced sampling (SBS) +- Two-stage cluster sampling ## Table of Contents @@ -46,7 +53,7 @@ The InPlotSampling package provides a way for researchers to easily implement Ra * [Sampling Methods](#sampling-methods) * [JPS Sampling](#jps-sampling) - * [RSS Sampling](#rss-sampling) + * [RSS](#rss-sampling) * [Installation](#installation) * [Examples](#examples) * [JPS Sample and Estimator](#jps-sample-and-estimator) @@ -64,17 +71,17 @@ Sampling is made following the diagram below. ![JPS sampling diagram](man/figures/jps-diagram.drawio.svg) -### RSS Sampling +### RSS Sampling is made following the diagram below. -![RSS sampling diagram](man/figures/rss-diagram.drawio.svg) +![RSS diagram](man/figures/rss-diagram.drawio.svg) ## Installation Use the following code to install this package: -```{r eval=F} +```{r, eval=F} if (!require("remotes")) install.packages("remotes") remotes::install_github("AAGI-AUS/InPlotSampling", upgrade = FALSE) ``` @@ -128,37 +135,37 @@ InPlotSampling::rss_jps_estimate( ### SBS PPS Sample and Estimator
- SBS PPS sample and estimator - - ``` 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 - ``` +SBS PPS sample and estimator + +``` 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 +```
# Citing this package From 2c782acac531db3208f8f349eb2532052742319f Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Fri, 14 Feb 2025 11:17:41 +1030 Subject: [PATCH 3/3] build readme --- README.md | 71 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 67fd670..c6f7780 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,13 @@ version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r- The InPlotSampling package provides a way for researchers to easily -implement Ranked Set Sampling in practice. +implement these sampling methods in practice. + +- Judgment post-stratified (JPS) sampling +- Ranked set sampling (RSS) +- Porbability-proportional to size (PPS) sampling +- Spatially balanced sampling (SBS) +- Two-stage cluster sampling ## Table of Contents @@ -30,7 +36,7 @@ implement Ranked Set Sampling in practice. - [Sampling Methods](#sampling-methods) - [JPS Sampling](#jps-sampling) - - [RSS Sampling](#rss-sampling) + - [RSS](#rss-sampling) - [Installation](#installation) - [Examples](#examples) - [JPS Sample and Estimator](#jps-sample-and-estimator) @@ -52,14 +58,13 @@ alt="JPS sampling diagram" /> -### RSS Sampling +### RSS Sampling is made following the diagram below.
- - +RSS diagram +
## Installation @@ -128,33 +133,33 @@ SBS PPS sample and estimator ``` 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 +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 ```