Skip to content

Commit

Permalink
Merge pull request #58 from WorldHealthOrganization/fix-overflow
Browse files Browse the repository at this point in the history
Fix overflow in zscore estimates
  • Loading branch information
dirkschumacher authored Nov 1, 2024
2 parents 9d92329 + eb2db42 commit e715811
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/prevalence-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ sample_size <- function(x, N, empty_data_prototype) {
}

sample_se <- function(x, x_mean, n, N) {
scale <- N / (N - 1) * 1 / (n * n)
scale <- N / (N - 1)
x_deviation <- x - x_mean
sqrt(sum(scale * x_deviation * x_deviation))
sqrt(scale)/n * sqrt(sum(x_deviation * x_deviation))
}
7 changes: 7 additions & 0 deletions tests/testthat/test-prevalence-simple-estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ test_that("survey and approximation yield are equal within tolerance", {
expect_equal(res_simple[[!!col]], res_survey[[!!col]], tolerance = 0.0001)
}
})

test_that("zscore estimates should not overflow", {
x <- rnorm(100000)
expect_no_warning(
zscore_estimate(x, length(x), data.frame())
)
})

0 comments on commit e715811

Please sign in to comment.