【发布时间】:2020-10-06 20:31:42
【问题描述】:
我有一个包含 1,224,647 个 p 值的不太大(嗯,“大”是相对的)数组/向量。
在我的 Ubuntu VM 上运行大约需要 15 分钟。长时间运行让我很困扰,因为这是我必须分析的数据的一小部分。
我已经阅读了手册,运行了搜索引擎,我没有看到其他人有这个问题,这非常令人费解。
我的会话信息:
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.3
我的脚本很简单:
setEPS()
postscript('p_values.histogram.eps')
hist(d, breaks=10, main = 'p values', xlab = 'p')
dev.off()
我可以编写一个脚本来计算每个直方图 bin,然后制作一个简化的数据集,但这对于这样的例行任务来说似乎太复杂了。
真正奇怪的是当我跑步时
t0 <- proc.time()
source("tmp.R")
t1 <- proc.time()
print(t1-t0)
x100 <- rnorm(100)
x1000 <- rnorm(1000)
x10000 <- rnorm(10000)
x100000 <- rnorm(100000)
x1000000 <- rnorm(1000000)
#
t0 <- proc.time()
hist(x100)
t1 <- proc.time()
print("100")
print(t1-t0)
#-------------
t0 <- proc.time()
hist(x1000)
t1 <- proc.time()
print("1000")
print(t1-t0)
#-------------
t0 <- proc.time()
hist(x10000)
t1 <- proc.time()
print("10000")
print(t1-t0)
#-------------
t0 <- proc.time()
hist(x100000)
t1 <- proc.time()
print("100000")
print(t1-t0)
#-------------
t0 <- proc.time()
hist(x1000000)
t1 <- proc.time()
print("1000000")
print(t1-t0)
pdf("tmp.pdf")
#-------------
t0 <- proc.time()
hist(d)
t1 <- proc.time()
print("d")
dev.off()
print(t1-t0)
hist 函数运行得非常快……但它不在脚本中。
如何在 R 中以更合理的时间范围生成此直方图?有什么我不知道的技巧吗?
【问题讨论】:
-
我认为它不应该改变任何东西,但是您是否尝试过使用其他设备,例如
pdf? -
@starja 不幸的是,运行 PDF 而不是 EPS 也非常慢。
-
你能告诉我们
str(d)吗?也许是一些奇怪的数据结构让hist()感到困惑? -
@BenBolker 的输出 `str(d) num [1:1224647] 0.5498 0.423 0.4605 0.0107 0.9394 ...
-
好吧,这是一个无聊的数字向量。我的测试功能在规模以下的表现如何?也许你的记忆力有限。 (尽管 1e7 的数字向量“仅”为 76 Mb)。您的环境中还有多少其他东西?