函数中的统计测试(R)

函数中的统计测试(R),r,statistics,time-series,R,Statistics,Time Series,希望是一个简单的编码问题:如何在函数中包含统计测试。具体来说,我正在处理时间序列,我想标记非平稳曲线。在R中我需要这样的东西: flag<- list() for (i in 1:length(obsv)) { if adf.test(i) FAIL { append(flag, i) }} 你可以看到,物体2是静止的,但3显示出一种趋势,1在3/09时有一个脉冲。因此,我想标记1和3 >library(tseries)

希望是一个简单的编码问题:如何在函数中包含统计测试。具体来说,我正在处理时间序列,我想标记非平稳曲线。在R中我需要这样的东西:

flag<- list()

for (i in 1:length(obsv)) {
     if adf.test(i) FAIL {
           append(flag, i) 
           }}
你可以看到,物体2是静止的,但3显示出一种趋势,1在3/09时有一个脉冲。因此,我想标记1和3

>library(tseries)

>adf.test(df[which(df$ID==1), 3])

Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.01
null hypothesis: non-stationary

>adf.test(df[which(df$ID==2), 3])

Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.99
alternative hypothesis: stationary


>adf.test(df[which(df$ID==3), 3])
Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.04
null hypothesis: non-stationary

我想要的是将测试结果合并到一个函数中。

标记曲线或标记变量?您应该给出一个可复制的示例。例如,您的时间序列/观测值是否为data.frame的列?你能解释一下失败(精确的条件)是什么意思吗?标记曲线——很抱歉混淆了。
>library(tseries)

>adf.test(df[which(df$ID==1), 3])

Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.01
null hypothesis: non-stationary

>adf.test(df[which(df$ID==2), 3])

Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.99
alternative hypothesis: stationary


>adf.test(df[which(df$ID==3), 3])
Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.04
null hypothesis: non-stationary