How can I get rateratio() to return more p-value digits?

Viewed 77

Using fmsb to calculate incidence rate ratios.

Example:

rr <- rateratio(853, 7703, 284, 3508)
rr
Cases   Person-time
Exposed    853     284
Unexposed 7703    3508
Total       8556    3792

Incidence rate ratio estimate and its significance probability

data: 853 7703 284 3508
p-value <2.2e-16
95 percent confidence interval:<br/>
1.274426 1.468068
sample estimates:
[1] 1.367824

Then when I try to return the values to store later in a table:

p <- rr$p.value
p
[1] 0

How can I change the format so that it returns the p-value with more digits? Preferably 3 or 4 or in scientific notation.

1 Answers

fmsb::rateratio() does an imprecise computation of the tail value of the Normal distribution, resulting in the value underflowing to zero. You can fix this yourself (it would be public-spirited to contact the maintainer (maintainer("fmsb")) to suggest this improvement to the package).

Save the source code of the function to a file:

dump("rateratio",file="my_rateratio.R")

Edit the file in a text editor (or RStudio or whatever) and change line 14, which is

p.v <- 2 * (1 - pnorm(abs(.CHI)))

to

p.v <- 2 * pnorm(abs(.CHI), lower=FALSE)

(which is an equivalent, but more accurate computation: see ?pnorm or here). Then read the file back in:

source("my_rateratio.R")

(this creates a new version of rateratio() in your global workspace, masking the version from fmsb).

Now if you re-run the code you'll see that rr$p.value is 2.893638e-18.

Related