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"))
Z | Z-statistic, numeric vector. |
---|---|
method |
|
P P-value, same length as Z.
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.
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
#> [1] 0.05000000 0.04999579z2p(20)#> [1] 5.507248e-89z2p(20, method = "Rmpfr::pnorm")#>#> 1 'mpfr' number of precision 100 bits #> [1] 5.507248237212467390151245560065e-89z2p(200, method = "pnorm") # the default#>#> [1] 0z2p(200, method = "Rmpfr::pnorm")#>#> 1 'mpfr' number of precision 100 bits #> [1] 5.143528423283502496154258642232e-8689