Skip to content

Commit

Permalink
Add explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Jun 26, 2023
1 parent 71648d6 commit 791103d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/testthat/helper-differentiate.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ expectation_continuous <- function(fd, pars, from, to) {
}


## Discrete distrbutions are somewhat harder
## Discrete distrbutions are somewhat harder. Take fd (the density 'd'
## function, e.g. dbinom) and fq (the corresponding quantile 'q'
## function, e.g., qbinom) and work out some suitably far out value
## that we capture at least 1-tol of the probability mass, then sum
## over that. This is not quite an infinite sum but at tolerance of
## 1e-12 we're around the limits of what we'd get summing over many
## floating point numbers (and this is only used in tests with a
## looser tolerance anyway)
expectation_discrete <- function(fd, fq, pars, tol = 1e-12) {
end <- do.call(fq, c(list(p = 1 - tol), unname(pars)))
n <- seq(0, end, by = 1)
Expand Down

0 comments on commit 791103d

Please sign in to comment.