Takes Z-statistic(s) as input and outputs P-value(s). This function works for absolute Z-statistics up to x

z2p(Z, method = c("pnorm"))

Arguments

Z

Z-statistic, numeric vector.

method

"prnorm" (default), "Rmpfr::pnorm" (from the Rmpfr package)

Value

P P-value, same length as Z.

Details

The usual P value calculation for |Z|-statistics < 38 is pnorm(abs(Z), lower.tail = FALSE) * 2 or, alternatively, exp(pnorm(abs(Z), log.p = TRUE, lower.tail = FALSE)) * 2. For anything that is larger, we can use the R package Rmpfr::pnorm that helps us with small digits.

References

See also this post: https://stackoverflow.com/questions/46416027/how-to-compute-p-values-from-z-scores-in-r-when-the-z-score-is-large-pvalue-muc

Examples

z2p(c(-1.959964, 1.96))
#> [1] 0.05000000 0.04999579
z2p(20)
#> [1] 5.507248e-89
z2p(20, method = "Rmpfr::pnorm")
#> using method Rmpfr::
#> 1 'mpfr' number of precision 100 bits #> [1] 5.507248237212467390151245560065e-89
z2p(200, method = "pnorm") # the default
#> Some P-values are equal to 0. Try using the option method = 'Rmpfr::pnorm'
#> [1] 0
z2p(200, method = "Rmpfr::pnorm")
#> using method Rmpfr::
#> 1 'mpfr' number of precision 100 bits #> [1] 5.143528423283502496154258642232e-8689