【问题标题】:Extract element from object of class "cpt" changepoint package从类“cpt”变更点包的对象中提取元素
【发布时间】:2014-04-22 06:30:18
【问题描述】:

包变更点

我想从下面的表达式 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

另一方面,我似乎没有在包中找到任何关于提取不同元素的说明。欢迎任何帮助

【问题讨论】:

    标签: r


    【解决方案1】:

    试试下面的(40不是变化点,只是你数据集的长度)

    cpts(cpDxu2)
    
    #cpt 
    #36 
    

    如果你想要它作为一个数字对象,做

    as.numeric(cpts(cpDxu2))
    

    【讨论】:

      猜你喜欢
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2023-01-10
      相关资源
      最近更新 更多