从类“cpt”changepoint包的对象中提取元素

时间:2014-04-21 22:18:30

标签: r

包更改点

我想从下面的表达式中提取Slot“cpts”:cpt 36 40并且无法弄清楚如何做到这一点。

x<-c(1,2,3,4,5,1,2,3,4,4,5,6,7,8,9,1,2,3,4,5,6,7,8,2,1,1,2,3,4,5,3,2,3,5,4,3,2,1,1,1)

cpt.meanvar(x,penalty="SIC",pen.value=0,method="AMOC",Q=5,test.stat="Normal")

An object of class "cpt"
Slot "data.set":
Time Series:
Start = 1 
End = 40 
Frequency = 1 
 [1] 1 2 3 4 5 1 2 3 4 4 5 6 7 8 9 1 2 3 4 5 6 7 8 2 1 1 2 3 4 5 3 2 3 5 4 3 2 1 1 1

Slot "cpttype":
[1] "mean and variance"

Slot "method":
[1] "AMOC"

Slot "test.stat":
[1] "Normal"

Slot "pen.type":
[1] "SIC"

Slot "pen.value":
[1] 7.377759

Slot "cpts":
cpt     
 36  40 

Slot "ncpts.max":
[1] 1

Slot "param.est":
$mean
[1] 3.833333 1.250000

$variance
[1] 4.657143 0.250000

Slot "date":
[1] "Fri Apr 18 07:51:17 2014"

尝试过

cpDxu2[[1]]
Error en cpDxu2[[1]] : this S4 class is not subsettable

cpDxu2$cpt
Error en cpDxu2$cpt : $ operator not defined for this S4 class

我想提取系数cpt 36 40

另一方面,我似乎没有找到包中可能提供的关于提取不同元素的任何指令。欢迎任何帮助

1 个答案:

答案 0 :(得分:1)

尝试以下操作(40不是更改点,只是数据集的长度)

cpts(cpDxu2)

#cpt 
#36 

如果您想将它作为数字对象,请执行

as.numeric(cpts(cpDxu2))