Skip to content

Commit

Permalink
Merge pull request #200 from ayushpatnaikgit/docs
Browse files Browse the repository at this point in the history
Finish remaining docs.
  • Loading branch information
smishr authored Feb 1, 2023
2 parents 9bd635f + 38bb764 commit 5f5b5f6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ makedocs(;
"Getting Started" => "getting_started.md",
"Manual" => [
"DataFrames in Survey" => "man/dataframes.md",
"ReplicateDesign" => "man/replicate.md",
"Replicate weights" => "man/replicate.md",
"Plotting" => "man/plotting.md",
"Comparison with other survey analysis tools" => "man/comparisons.md",
"Future plans" => "man/future.md",
],
"API reference" => "api.md",
],
Expand Down
1 change: 0 additions & 1 deletion docs/src/man/future.md

This file was deleted.

42 changes: 41 additions & 1 deletion docs/src/man/replicate.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# ReplicateDesign
# Replicate weights

Replicate weights are a method for estimating the standard errors of survey statistics in complex sample designs.

The basic idea behind replicate weights is to create multiple versions of the original sample weights, each with small, randomly generated perturbations. The multiple versions of the sample weights are then used to calculate the survey statistic of interest, such as the mean or total, on multiple replicate samples. The variance of the survey statistic is then estimated by computing the variance across the replicate samples.

Currently, the Rao-Wu bootstrap[^1] is the only method in the package for generating replicate weights.

The `bootweights` function of the package can be used to generate a `ReplicateDesign` from a `SurveyDesign`
For example:
```@repl bootstrap
using Survey
apistrat = load_data("apistrat")
strat = SurveyDesign(apistrat; strata=:stype, weights=:pw)
strat_boot = bootweights(strat; replicates = 10)
```

For each replicate, the `DataFrame` of `ReplicateDesign` has an additional column. The of the column is `replicate_` followed by the replicate number.

```@repl bootstrap
names(strat_boot.data)
```
`replicate_1`, `replicate_2`, `replicate_3`, `replicate_4`, `replicate_5`, `replicate_6`, `replicate_7`, `replicate_8`, `replicate_9`, `replicate_10`, are the replicate weight columns.

While a `SurveyDesign` can be used to estimate a statistics. For example:

```@repl bootstrap
mean(:api00, strat)
```

The `ReplicateDesign` can be used to compute the standard error of the statistic. For example:

```@repl bootstrap
mean(:api00, strat_boot)
```

For each replicate weight, the statistic is calculated using it instead of the weight. The standard deviation of those statistics is the standard error of the estimate.

## References

[^1]: [Rust, Keith F., and J. N. K. Rao. "Variance estimation for complex surveys using replication techniques." Statistical methods in medical research 5.3 (1996): 283-310.](https://journals.sagepub.com/doi/abs/10.1177/096228029600500305?journalCode=smma)
6 changes: 4 additions & 2 deletions test/quantile.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@testset "quantile_SimpleRandomSample" begin
@test quantile(:api00, srs, 0.5)[!,1][1] 659.0 atol=1e-4
@test quantile(:api00, srs_boot, 0.5)[!,1][1] 659.0 atol=1e-4
@test quantile(:api00, srs_boot, [0.1753,0.25,0.5,0.75,0.975])[!,2] [512.8847,544,659,752.5,905] atol = 1e-4
@test quantile(:enroll,srs_boot, [0.1,0.2,0.5,0.75,0.95])[!,2] [245.5,317.6,453.0,668.5,1473.1] atol = 1e-4
@test quantile(:api00, srs_boot, [0.1753,0.25,0.5,0.75,0.975])[!,2] [512.8847,544,659,752.5,905] rtol = 1e-4
@test quantile(:api00, srs_boot, [0.1753,0.25,0.5,0.75,0.975])[!,3] [14.6761,12.7793,14.9763,10.7707,11.2990] rtol = 1e-4
@test quantile(:enroll,srs_boot, [0.1,0.2,0.5,0.75,0.95])[!,2] [245.5,317.6,453.0,668.5,1473.1] rtol = 1e-4
@test quantile(:enroll,srs, [0.1,0.2,0.5,0.75,0.95])[!,2] [245.5,317.6,453.0,668.5,1473.1] rtol = 1e-4
end

0 comments on commit 5f5b5f6

Please sign in to comment.