Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
97e7968
Match sample rows to the frame by a .row column and copy the frame
elkronos Nov 13, 2026
b5a8bde
Check a weighted sample against its state at draw time
elkronos Nov 13, 2026
0c4cf6e
Hold units taken with certainty fixed in the variance estimators
elkronos Nov 13, 2026
2140bb3
Leave units taken with certainty out of the degrees of freedom
elkronos Nov 13, 2026
7248299
Key groups by integer codes in byte order and look them up by position
elkronos Nov 13, 2026
d960edb
Compare clusters by integer codes and tighten multistage checks
elkronos Nov 13, 2026
fed93db
Catch only declines in the variance dispatch and refuse unmeasurable …
elkronos Nov 13, 2026
02c4b5b
Add proportion intervals and one-sided bounds, and count reachable rows
elkronos Nov 13, 2026
b85c585
Compute SRS-type variances in closed form and cap joint_prob() size
elkronos Nov 13, 2026
b510bf1
Estimate all domains in one pass and add domain contrasts
elkronos Nov 13, 2026
be8c2ba
Share feasibility checks between draw() and the probability paths
elkronos Nov 13, 2026
23ca9ea
Keep the allocation rule under a floor and accept per-stratum counts
elkronos Nov 13, 2026
d6b138f
Take Neyman spreads and costs per stratum, and preview the allocation
elkronos Nov 13, 2026
ced142a
Lay out temporal windows in the data's zone and on calendar days
elkronos Nov 13, 2026
e0c0e97
Check spatial regions and coordinates, and read geometry and dates
elkronos Nov 13, 2026
a9a98b4
Spread a sample within strata, and let tiny probabilities compete
elkronos Nov 13, 2026
26851b8
Sample list positions directly and add circular and matrix bootstraps
elkronos Nov 13, 2026
a6b5758
Read reservoir connections in blocks and sample rows of batches
elkronos Nov 13, 2026
a75f3d6
Let design_systematic() draw a fixed n at a fractional step
elkronos Nov 13, 2026
f19da67
Add replicated starts and systematic sampling within strata
elkronos Nov 13, 2026
101fde6
Sample in proportion to size within strata and select clusters by size
elkronos Nov 13, 2026
930adca
Weight balanced and uneven-take cluster samples on their selection
elkronos Nov 13, 2026
7102081
Hand certainty compositions and one-row clusters to survey
elkronos Nov 13, 2026
49bec27
Add replicate weights and frame totals for the survey hand-off
elkronos Nov 13, 2026
53cfd2e
Add estimate methods, a deff generic and fuller sample summaries
elkronos Nov 13, 2026
9b04f0a
Rebuild, join and compact samples, and estimate means with missing y
elkronos Nov 13, 2026
c466630
Add reserve lists and use_reserves() for unreachable units
elkronos Nov 13, 2026
ec88f4d
Add ht_ratio(), ratio totals and several y at once
elkronos Nov 13, 2026
bef7cf4
Add ht_quantile() and per-level shares and counts for factor y
elkronos Nov 13, 2026
28637d9
Fix plan_size() sizing, argument checks and design effect advice
elkronos Nov 13, 2026
27a728f
Plan stratified samples and take a plan as n
elkronos Nov 13, 2026
39cbf0a
Show every row in the probability and selection plots
elkronos Nov 13, 2026
bae72d8
Check plot arguments, fix the map notes and widen design titles
elkronos Nov 13, 2026
ed9c299
Pin the seed's generator, keep row names and tame simulation output
elkronos Nov 13, 2026
f28078b
Correct documented claims that overstated the code and simulations
elkronos Nov 13, 2026
0967b86
Check every design on every path, and sharpen weak tests
elkronos Nov 13, 2026
be65f09
Test R 4.1 in CI, sharpen the doc guards and fix package metadata
elkronos Nov 13, 2026
2b14df7
Check samples saved by drawn 0.2.0 and keep S4 columns in copies
elkronos Nov 14, 2026
608e55c
Give clusters taken whole their own survey stratum and fix notes
elkronos Nov 14, 2026
6de47f5
Sort unmarked non-ASCII keys and keep NULL choices at their default
elkronos Nov 14, 2026
58d1746
Tighten domain variance declines and proportion intervals
elkronos Nov 14, 2026
d767216
Name missing joint probabilities first and count truncated lists
elkronos Nov 14, 2026
34c90d0
Split far-apart Neyman shares and order mixed time bounds at use
elkronos Nov 14, 2026
317ea57
Warn on -180 to 180 edges and count only kept rows per stratum
elkronos Nov 14, 2026
eafeac3
Give back the look-ahead line at block edges and scope systematic claims
elkronos Nov 14, 2026
3a2a1b9
Hand one-row multistage size samples to survey in one stage
elkronos Nov 14, 2026
063055c
Scope survey's replicate jackknife and fill SDR replicates in blocks
elkronos Nov 14, 2026
76a76c7
Check rebuilt rows against the frame and leave unknown covariances NA
elkronos Nov 14, 2026
68cb5a6
Refuse survey estimates as deff and unfloored stratified plans
elkronos Nov 14, 2026
d7208e2
Take plotmath names as titles and count varied simulation warnings
elkronos Nov 14, 2026
ee8c9ef
Draw map outlines without lwgeom and time runs past warm-up draws
elkronos Nov 16, 2026
1fc8b38
Refuse reordered 0.2.0 samples and upgrade saved designs on entry
elkronos Nov 16, 2026
10e8760
Label Latin-1 text by byte and estimate means inside census clusters
elkronos Nov 16, 2026
149e850
Reuse jackknife strata across domains and order far-off window bounds
elkronos Nov 16, 2026
d0afaa1
Refuse frame totals of session values and file certain rows by design
elkronos Nov 16, 2026
0d1920c
Read infinities, T/F text and UTC times back as the frame's
elkronos Nov 16, 2026
3702df6
Refuse empty or multi-part plot titles and scope varied warnings
elkronos Nov 16, 2026
83bacf9
Decline one-cluster domains under the jackknife and trust id order
elkronos Nov 17, 2026
7f5b84f
Hold the macOS tests and README check across platforms and tools
elkronos Nov 17, 2026
4d9c24c
Accept 1e-300 as parsed without extended precision
elkronos Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
^Rplots\.pdf$
^README\.Rmd$
^vignettes/articles$
^\.stage$
^drawn$
^CRAN-AUDIT\..*$
^RUNBOOK\.md$
89 changes: 80 additions & 9 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Derived from https://github.com/r-lib/actions/tree/v2/examples
#
# Checks the package on macOS, Windows and Linux, against the current R release,
# the previous one, and R-devel. R-devel is the one that catches deprecations
# before CRAN does; oldrel-1 backs up the `R (>= 4.1)` claim in DESCRIPTION.
# Checks the package on macOS and Windows against the current R release, and
# on Linux against R-devel, the release, the previous release (oldrel-1) and
# R 4.1. R-devel is the one that catches deprecations before CRAN does; the
# R 4.1 leg backs up the `R (>= 4.1)` claim in DESCRIPTION, which oldrel-1
# does not reach. One more Linux leg builds the PDF manual, fails on any
# NOTE, and checks that README.md was rendered from the current README.Rmd.
on:
push:
branches: [main, master]
Expand All @@ -23,7 +26,10 @@ jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
name: ${{ matrix.config.os }} (${{ matrix.config.r }}${{ matrix.config.strict && ', strict' || '' }})

# Stops a hung job after an hour rather than the six-hour default.
timeout-minutes: 60

strategy:
fail-fast: false
Expand All @@ -33,12 +39,16 @@ jobs:
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release', strict: true}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: '4.1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
# Surface anything the tests only warn about.
# Lets R CMD check run when a Suggests package is missing. The
# dependency step below installs every Suggests package and fails the
# job if one cannot be installed, so on these runners none is missing.
_R_CHECK_FORCE_SUGGESTS_: false

steps:
Expand All @@ -52,27 +62,88 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

# LaTeX for the PDF manual. Rd.sty sets code in Inconsolata.
- uses: r-lib/actions/setup-tinytex@v2
if: matrix.config.strict

- name: Install the Inconsolata font package
if: matrix.config.strict
run: tlmgr install inconsolata

# HTML Tidy validates the HTML manual; without it the strict check
# reports a NOTE that it skipped the validation.
- name: Install HTML Tidy
if: matrix.config.strict
run: |
sudo apt-get update
sudo apt-get install -y tidy

# `sf` is a Suggests-only dependency and needs GDAL, GEOS and PROJ.
# setup-r-dependencies installs the Linux system libraries itself; macOS
# and Windows get binaries. If it ever fails to install on one platform
# the spatial tests skip rather than fail, which is why they are written
# with skip_if_not_installed("sf").
# and Windows get binaries. If `sf` or any other Suggests package fails
# to install, this step fails the job. The spatial tests are written
# with skip_if_not_installed("sf") for machines without it, such as
# some CRAN check machines.
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- name: No duplicate function definitions under R/
run: Rscript tools/check-duplicates.R
run: |
Rscript tools/check-duplicates.R --self-test
Rscript tools/check-duplicates.R
shell: bash

- name: Documentation is consistent with the code
run: |
Rscript tools/check-docs.R --self-test
R CMD INSTALL --no-multiarch --with-keep.source .
Rscript tools/check-docs.R
shell: bash

# The sample summary in the README prints the date it was drawn, so a
# change confined to that line is ignored. Pandoc and knitr versions lay
# out tables and error output differently, so both copies are compared
# with table padding removed and an error on two lines ("Error:" then
# "! message") joined into one; the words still have to match.
- name: README.md is rendered from README.Rmd
if: matrix.config.strict
run: |
cp README.md "$RUNNER_TEMP/README.committed.md"
Rscript -e 'rmarkdown::render("README.Rmd", output_options = list(html_preview = FALSE), quiet = TRUE)'
normalise() {
sed -E -e '/^#> +drawn +with seed/d' \
-e '/^\|/{s/ *\| */|/g; s/-{2,}/-/g}' \
-e '/^#> (Error|Warning)( in .*)?:$/{N;s/\n#> ! / /}' "$1"
}
diff -u <(normalise "$RUNNER_TEMP/README.committed.md") <(normalise README.md) || {
echo "README.md differs from a fresh render of README.Rmd; run devtools::build_readme() and commit README.md."
exit 1
}
shell: bash

- uses: r-lib/actions/check-r-package@v2
if: ${{ !matrix.config.strict }}
with:
upload-snapshots: true
build_args: 'c("--no-manual", "--compact-vignettes=gs+qpdf")'
error-on: '"warning"'

# The incoming checks are off because a first submission always gets
# the "New submission" NOTE; every other NOTE fails this leg.
# --as-cran turns on the check for files dated in the future, which
# asks worldtimeapi.org for the time and gives the NOTE "unable to
# verify current time" when that service does not answer. Turning off
# _R_CHECK_SYSTEM_CLOCK_ keeps the file check against the runner's own
# clock and drops the call to the service.
- uses: r-lib/actions/check-r-package@v2
if: ${{ matrix.config.strict }}
env:
_R_CHECK_CRAN_INCOMING_: false
_R_CHECK_SYSTEM_CLOCK_: false
with:
upload-snapshots: true
args: 'c("--as-cran")'
build_args: 'c("--compact-vignettes=gs+qpdf")'
error-on: '"note"'
6 changes: 6 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Derived from https://github.com/r-lib/actions/tree/v2/examples
#
# A pull request builds the site, which knits the articles under
# vignettes/articles that R CMD build leaves out and checks the reference
# index, but does not deploy it.
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:
Expand Down Expand Up @@ -43,3 +48,4 @@ jobs:
clean: false
branch: gh-pages
folder: docs
commit-message: Deploy site from ${{ github.sha }}
38 changes: 22 additions & 16 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
Package: drawn
Title: Design-Based Sampling with Known Inclusion Probabilities
Version: 0.2.0
Version: 0.2.0.9000
Authors@R:
person("Justin", "Chase", email = "jchase.msu@gmail.com",
role = c("aut", "cre"))
Description: Draws probability samples from data frames under an explicit,
reusable sampling design: simple random, stratified (proportional, equal
or Neyman), systematic, cluster, multi-stage, probability-proportional-to-
size, certainty-plus-sample, spatially balanced (the local pivotal method
of Grafstrom, Lundstrom and Schelin, 2012), reservoir, bootstrap,
or Neyman), systematic, cluster, multi-stage,
probability-proportional-to-size, certainty-plus-sample, spatially
balanced (the local pivotal method of Grafström, Lundström and Schelin
(2012) <doi:10.1111/j.1541-0420.2011.01699.x>), reservoir, bootstrap,
temporal and region-restricted. A design is a value that can be stored,
printed and reused, and that knows its own first- and second-order
inclusion probabilities, so a drawn sample carries the weights needed for
Horvitz-Thompson estimation: 'ht_total()' and 'ht_mean()' return a
population total, mean or proportion, overall or by domain, with a
standard error, a confidence interval on the design's degrees of freedom
and a design effect. Each design gets the variance estimator the
literature recommends for it, and says which: Sen-Yates-Grundy where joint
probabilities are known, Deville's approximation for
probability-proportional-to-size, successive differences for systematic
samples, local means for spatially balanced ones, and a stratified
jackknife otherwise. 'plan_size()' solves for the sample size a target
margin of error requires, and 'as_svydesign()' hands a sample to the
Horvitz-Thompson estimation: ht_total() and ht_mean() return a population
total, mean or proportion, overall or by domain, with a standard error, a
confidence interval on the design's degrees of freedom and a design
effect. Each design gets the variance estimator the literature recommends
for it, and says which: Sen-Yates-Grundy where joint probabilities are
known, the exact Horvitz-Thompson variance for Poisson sampling, the
approximation of Deville (1999) for systematic
probability-proportional-to-size samples, successive differences for
systematic samples, local means for spatially balanced ones, and a
stratified jackknife otherwise. plan_size() solves for the sample size a
target margin of error requires, and as_svydesign() hands a sample to the
'survey' package for further analysis. Designs whose inclusion
probabilities have no closed form report that rather than supplying an
approximation, and can be estimated by simulation instead.
License: GPL-3
Encoding: UTF-8
Language: en-GB
Depends:
R (>= 4.1)
Imports:
graphics,
lubridate,
grDevices,
lubridate (>= 1.9.0),
stats,
utils
Suggests:
data.table,
generics,
sampling,
sf (>= 1.0.0),
survey,
testthat (>= 3.0.0),
testthat (>= 3.1.7),
tibble,
knitr,
rmarkdown
Expand Down
59 changes: 59 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,drawn_by)
S3method(as.data.frame,drawn_contrast)
S3method(as.data.frame,drawn_ht)
S3method(as.data.frame,drawn_mean)
S3method(as.data.frame,drawn_plan)
S3method(as.data.frame,drawn_quantile)
S3method(as.data.frame,drawn_ratio)
S3method(coef,drawn_by)
S3method(coef,drawn_contrast)
S3method(coef,drawn_ht)
S3method(coef,drawn_mean)
S3method(coef,drawn_quantile)
S3method(coef,drawn_ratio)
S3method(confint,drawn_by)
S3method(confint,drawn_contrast)
S3method(confint,drawn_ht)
S3method(confint,drawn_mean)
S3method(confint,drawn_quantile)
S3method(confint,drawn_ratio)
S3method(deff,default)
S3method(deff,drawn_by)
S3method(deff,drawn_contrast)
S3method(deff,drawn_ht)
S3method(deff,drawn_mean)
S3method(deff,drawn_quantile)
S3method(deff,drawn_ratio)
S3method(draw_design,default)
S3method(draw_design,drawn_design_bootstrap)
S3method(draw_design,drawn_design_certainty)
Expand All @@ -13,17 +39,42 @@ S3method(draw_design,drawn_design_stratified)
S3method(draw_design,drawn_design_systematic)
S3method(draw_design,drawn_design_temporal)
S3method(draw_design,drawn_design_weighted)
S3method(generics::tidy,drawn_by)
S3method(generics::tidy,drawn_contrast)
S3method(generics::tidy,drawn_ht)
S3method(generics::tidy,drawn_mean)
S3method(generics::tidy,drawn_quantile)
S3method(generics::tidy,drawn_ratio)
S3method(plot,drawn_design)
S3method(print,drawn_by)
S3method(print,drawn_contrast)
S3method(print,drawn_design)
S3method(print,drawn_ht)
S3method(print,drawn_mean)
S3method(print,drawn_plan)
S3method(print,drawn_quantile)
S3method(print,drawn_ratio)
S3method(print,drawn_summary)
S3method(survey::deff,drawn_by)
S3method(survey::deff,drawn_contrast)
S3method(survey::deff,drawn_ht)
S3method(survey::deff,drawn_mean)
S3method(survey::deff,drawn_quantile)
S3method(survey::deff,drawn_ratio)
S3method(vcov,drawn_by)
S3method(vcov,drawn_contrast)
S3method(vcov,drawn_ht)
S3method(vcov,drawn_mean)
S3method(vcov,drawn_quantile)
S3method(vcov,drawn_ratio)
export(add_fieldwork)
export(allocation_table)
export(as_drawn)
export(as_svydesign)
export(certainty_set)
export(compact_sample)
export(deff)
export(deff_cluster)
export(design_bootstrap)
export(design_certainty)
export(design_cluster)
Expand All @@ -38,16 +89,24 @@ export(design_temporal)
export(design_weighted)
export(draw)
export(draw_design)
export(frame_totals)
export(ht_mean)
export(ht_quantile)
export(ht_ratio)
export(ht_total)
export(inclusion_prob)
export(is_design)
export(joint_prob)
export(plan_size)
export(replicate_weights)
export(sample_summary)
export(sampling_weight)
export(use_reserves)
importFrom(graphics,abline)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(stats,coef)
importFrom(stats,confint)
importFrom(stats,vcov)
Loading
Loading