Reading a very small p-value in R

Viewed 375

I am using R and I was encountering problem to calculate p-value for a large z-score for some genes. I used Rmpfr package to make it work using the following code (thanks to this forum)

2*Rmpfr::pnorm(mpfr(abs(38.77589104), precBits=100), lower.tail=FALSE, log.p = FALSE)
6.5625457492544973317295147124225e-329

I enter the above value as 6.56E-329. Now, the problem is when I am trying to read the file containing all p-values, it again reads the above value as 0.

pval <- file$pvalue
pval[1]
[1] 0
pval[1] <- 6.56E-329
pval[1]
[1] 0

I need the exact value for further downstream analysis. Is there a way to read the value as it is in a file?

Much appreciated! Thanks

1 Answers

How did you create the file of p-values? Unless you used save() and load() you strippd the precision when you saved them:

library(Rmpfr)
pval <- 2*Rmpfr::pnorm(mpfr(abs(38.77589104), precBits=100), lower.tail=FALSE, log.p = FALSE)
pval
# 1 'mpfr' number of precision  100   bits 
# [1] 6.5625457492544973317295147124225e-329
save(pval, file="Test.RData")
rm(pval)
pval
# Error: object 'pval' not found
load("Test.RData")
pval
# 1 'mpfr' number of precision  100   bits 
# [1] 6.5625457492544973317295147124225e-329

You can import extended precision values as character strings and mpfr will convert them:

example <- c("1.4142135623730951454746218587388", "1.7320508075688771931766041234368", 
"2.2360679774997898050514777423814", "2.6457513110645907161710965738166", 
"3.3166247903553998099823729717173")
mpfr(example)
# 5 'mpfr' numbers of precision  107   bits 
# [1] 1.414213562373095145474621858738804 1.732050807568877193176604123436797 2.236067977499789805051477742381394
# [4] 2.645751311064590716171096573816588 3.316624790355399809982372971717293
mpfr(example)^2
# 5 'mpfr' numbers of precision  107   bits 
# [1] 2.000000000000000273432346306476854 2.999999999999999652374485391952952 5.000000000000000485863154281767975
# [4] 7.000000000000000664980387281581168 10.99999999999999974042396434698263
Related