-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from ayushpatnaikgit/docs
Finish remaining docs.
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |