【发布时间】:2019-10-20 15:54:59
【问题描述】:
我最初的目标是进行测试并获得 pvalue。 我使用了OneSampleTTest,它看起来很有希望,但结果最终出现在标准输出中,如下所示:
julia> OneSampleTTest([1,2,3,4,5],3.1)
One sample t-test
-----------------
Population details:
parameter of interest: Mean
value under h_0: 3.1
point estimate: 3.0
95% confidence interval: (1.0368, 4.9632)
Test summary:
outcome with 95% confidence: fail to reject h_0
two-sided p-value: 0.8944
Details:
number of observations: 5
t-statistic: -0.14142135623730961
degrees of freedom: 4
empirical standard error: 0.7071067811865476
我想获取这个值:
two-sided p-value: 0.8944
为了重定向标准输出,我在我们的网站上找到了this。但似乎 OneSampleTTest 的输出不受此影响。
julia> using HypothesisTests
julia> original_stdout = stdout
Base.TTY(RawFD(0x0000001b) open, 0 bytes waiting)
julia> (rd, wr) = redirect_stdout()
(Base.PipeEndpoint(RawFD(0x00000020) open, 0 bytes waiting), Base.PipeEndpoint(RawFD(0x00000025) open, 0 bytes waiting))
julia> println("test")
julia> s = readline(rd)
"test"
julia> s == "test"
true
julia> OneSampleTTest([1,2,3,4,5],3.1)
One sample t-test
-----------------
Population details:
parameter of interest: Mean
value under h_0: 3.1
point estimate: 3.0
95% confidence interval: (1.0368, 4.9632)
Test summary:
outcome with 95% confidence: fail to reject h_0
two-sided p-value: 0.8944
Details:
number of observations: 5
t-statistic: -0.14142135623730961
degrees of freedom: 4
empirical standard error: 0.7071067811865476
julia>
如果有另一个s = readline(rd) 它会卡住,因为 rd 中没有任何内容。 (我假设)
解决此问题的唯一其他想法是尝试将测试结果写入文件并再次解析该文件。但我想进行数百万次 t 检验并使用文件来存储结果并每次都重新读取它们,这听起来像是一项糟糕的性能工作。
【问题讨论】:
标签: julia stdout p-value t-test