Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Dec 18, 2024
1 parent 9b093ff commit 80b7e3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/testthat/_snaps/rescale_weights.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
5 0.3119698 0.3060151 0.2152722
6 0.5155503 0.5858662 0.4121388

---

Code
head(rescale_weights(nhanes_sample, probability_weights = "WTINT2YR", method = "kish"))
Output
# A tibble: 6 x 8
total age RIAGENDR RIDRETH1 SDMVPSU SDMVSTRA WTINT2YR pweights
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 2.2 1 3 2 31 97594. 1.40
2 7 2.08 2 3 1 29 39599. 0.566
3 3 1.48 2 1 2 42 26620. 0.381
4 4 1.32 2 4 2 33 34999. 0.500
5 1 2 2 1 1 41 14746. 0.211
6 6 2.2 2 4 1 38 28232. 0.404

# rescale_weights nested works as expected

Code
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rescale_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("rescale_weights works as expected", {
expect_equal(sum(out$pweights_a), 2992, tolerance = 1e-3)
expect_equal(sum(out$pweights_b), 2244.71451, tolerance = 1e-3)
out <- rescale_weights(nhanes_sample, probability_weights = "WTINT2YR", method = "kish")
expect_equal(sum(out$pweights_b), 2162.53961, tolerance = 1e-3)
expect_equal(sum(out$pweights), 2162.53961, tolerance = 1e-3)
})


Expand Down

0 comments on commit 80b7e3a

Please sign in to comment.