禁止打印到屏幕的平稳性测试输出 [英] Suppress output of stationarity test that is printed to screen

查看:82
本文介绍了禁止打印到屏幕的平稳性测试输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 fractal package中获取stationarity测试R中的不会在屏幕上显示任何输出.

How do I get the stationarity test from the fractal package in R to not print any output to the screen.

例如,在shapiro.wilk测试中,将结果设置为变量时,它不会产生任何如下输出

For example, with the shapiro.wilk test when setting the result as a variable it does not give any output as follows

lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)

shap.p <- shapiro.test(lg.day.ret.vec)$p.value

大多数测试都是这种情况,但是当我进行stationarity测试时,我会在r控制台中得到一些输出.

This is the case for most tests but when I do it for the stationarity test I get some output in the r console.

library(fractal)

stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
1
2
3
4
5
6
N = 2609, nblock = 11, n_block_max = 238, dt =     1.0000
7
8
9
10
11
12
13
14
15
16
17
18

推荐答案

实际上,您可以通过重新路由来禁止输出到R控制台. R utils sinkcapture.output中提供了两种方法.两种方法都旨在将输出发送到文件.

In fact, you can suppress the output to R console by rerouting it. Two methods are available in R utils, sink, and capture.output. Both methods are intended to send output to a file.

由于要取消单个表达式的输出,因此可以将capture.outputfile=NULL一起使用(默认).这将返回您的输出作为字符串.为了防止在R控制台中显示此返回的字符串,可以使用invisible.

Since you want to suppress the output of a single expression, you can use capture.output, with file=NULL (default). This will return your output as a string. To prevent showing this returned string in the R console, you can use invisible.

最终代码可以是:

library(fractal)

lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)
shap.p <- shapiro.test(lg.day.ret.vec)$p.value

invisible(capture.output(
    stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
))

希望这会有所帮助.让我知道是否可以.

Hope this helps. Let me know if not.

这篇关于禁止打印到屏幕的平稳性测试输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆