Skip to contents

Retrieve the indices of the changepoints identified by an algorithm or model.

Usage

changepoints(x, ...)

# Default S3 method
changepoints(x, ...)

# S3 method for class 'mod_cpt'
changepoints(x, ...)

# S3 method for class 'seg_basket'
changepoints(x, ...)

# S3 method for class 'seg_cpt'
changepoints(x, ...)

# S3 method for class 'tidycpt'
changepoints(x, use_labels = FALSE, ...)

# S3 method for class 'ga'
changepoints(x, ...)

# S3 method for class 'cpt'
changepoints(x, ...)

# S3 method for class 'wbs'
changepoints(x, ...)

Arguments

x

A tidycpt, segmenter, or mod_cpt object

...

arguments passed to methods

use_labels

return the time labels for the changepoints instead of the indices.

Value

a numeric vector of changepoint indices, or, if use_labels is TRUE, a character of time labels.

Details

tidycpt objects, as well as their segmenter and model components, implement changepoints() methods.

Note that this function is not to be confused with wbs::changepoints(), which returns different information.

For the default method, changepoints() will attempt to return the cpt_true attribute, which is set by test_set().

See also

wbs::changepoints()

Other tidycpt-generics: as.model(), as.segmenter(), diagnose(), fitness(), model_name()

Examples

cpts <- segment(DataCPSim, method = "ga", maxiter = 5)
changepoints(cpts$segmenter)
#>    x4    x7   x13   x19   x20   x23   x24   x25   x26   x27   x28   x29   x31 
#>     4     7    13    19    20    23    24    25    26    27    28    29    31 
#>   x32   x38   x39   x40   x42   x47   x48   x49   x51   x54   x57   x58   x59 
#>    32    38    39    40    42    47    48    49    51    54    57    58    59 
#>   x67   x72   x73   x76   x77   x78   x82   x84   x85   x87   x91   x92   x93 
#>    67    72    73    76    77    78    82    84    85    87    91    92    93 
#>   x94   x98  x102  x104  x106  x108  x109  x112  x113  x115  x118  x122  x124 
#>    94    98   102   104   106   108   109   112   113   115   118   122   124 
#>  x125  x133  x134  x136  x138  x141  x142  x145  x146  x154  x158  x161  x163 
#>   125   133   134   136   138   141   142   145   146   154   158   161   163 
#>  x164  x165  x166  x167  x169  x170  x171  x172  x174  x178  x182  x183  x185 
#>   164   165   166   167   169   170   171   172   174   178   182   183   185 
#>  x187  x188  x190  x191  x195  x196  x197  x199  x200  x202  x205  x207  x210 
#>   187   188   190   191   195   196   197   199   200   202   205   207   210 
#>  x213  x214  x216  x219  x225  x230  x231  x236  x240  x242  x243  x247  x253 
#>   213   214   216   219   225   230   231   236   240   242   243   247   253 
#>  x254  x255  x259  x260  x262  x263  x265  x266  x268  x269  x270  x271  x272 
#>   254   255   259   260   262   263   265   266   268   269   270   271   272 
#>  x275  x278  x279  x280  x281  x282  x283  x285  x287  x288  x289  x290  x291 
#>   275   278   279   280   281   282   283   285   287   288   289   290   291 
#>  x293  x294  x295  x300  x302  x305  x312  x314  x315  x316  x318  x319  x321 
#>   293   294   295   300   302   305   312   314   315   316   318   319   321 
#>  x326  x327  x328  x329  x330  x331  x333  x335  x336  x338  x339  x347  x348 
#>   326   327   328   329   330   331   333   335   336   338   339   347   348 
#>  x350  x351  x354  x356  x357  x362  x364  x366  x369  x370  x371  x372  x376 
#>   350   351   354   356   357   362   364   366   369   370   371   372   376 
#>  x377  x382  x383  x384  x389  x390  x391  x396  x397  x404  x405  x406  x407 
#>   377   382   383   384   389   390   391   396   397   404   405   406   407 
#>  x408  x411  x412  x414  x415  x417  x418  x422  x423  x428  x429  x432  x435 
#>   408   411   412   414   415   417   418   422   423   428   429   432   435 
#>  x437  x439  x440  x442  x443  x445  x446  x447  x448  x450  x451  x452  x453 
#>   437   439   440   442   443   445   446   447   448   450   451   452   453 
#>  x455  x457  x458  x463  x466  x469  x470  x471  x473  x476  x477  x479  x480 
#>   455   457   458   463   466   469   470   471   473   476   477   479   480 
#>  x482  x485  x488  x490  x491  x492  x497  x500  x502  x503  x506  x507  x509 
#>   482   485   488   490   491   492   497   500   502   503   506   507   509 
#>  x512  x513  x515  x518  x522  x525  x527  x529  x530  x532  x534  x535  x536 
#>   512   513   515   518   522   525   527   529   530   532   534   535   536 
#>  x537  x538  x540  x541  x542  x543  x545  x548  x553  x559  x563  x564  x565 
#>   537   538   540   541   542   543   545   548   553   559   563   564   565 
#>  x566  x569  x570  x575  x577  x580  x585  x586  x587  x590  x591  x593  x595 
#>   566   569   570   575   577   580   585   586   587   590   591   593   595 
#>  x597  x600  x601  x602  x603  x606  x607  x610  x612  x613  x614  x615  x619 
#>   597   600   601   602   603   606   607   610   612   613   614   615   619 
#>  x620  x621  x624  x630  x631  x633  x634  x635  x639  x641  x642  x645  x646 
#>   620   621   624   630   631   633   634   635   639   641   642   645   646 
#>  x647  x648  x652  x653  x656  x658  x660  x662  x663  x664  x665  x668  x669 
#>   647   648   652   653   656   658   660   662   663   664   665   668   669 
#>  x670  x671  x675  x676  x678  x679  x681  x685  x688  x689  x690  x697  x699 
#>   670   671   675   676   678   679   681   685   688   689   690   697   699 
#>  x700  x702  x704  x706  x707  x712  x713  x714  x716  x718  x719  x720  x721 
#>   700   702   704   706   707   712   713   714   716   718   719   720   721 
#>  x723  x725  x726  x729  x731  x733  x734  x735  x737  x738  x740  x744  x746 
#>   723   725   726   729   731   733   734   735   737   738   740   744   746 
#>  x747  x748  x752  x754  x755  x756  x757  x759  x761  x762  x766  x767  x770 
#>   747   748   752   754   755   756   757   759   761   762   766   767   770 
#>  x771  x773  x777  x779  x781  x782  x783  x784  x787  x788  x790  x791  x793 
#>   771   773   777   779   781   782   783   784   787   788   790   791   793 
#>  x797  x799  x802  x803  x804  x805  x809  x810  x811  x812  x817  x820  x822 
#>   797   799   802   803   804   805   809   810   811   812   817   820   822 
#>  x824  x825  x827  x832  x833  x836  x837  x839  x841  x842  x843  x846  x848 
#>   824   825   827   832   833   836   837   839   841   842   843   846   848 
#>  x852  x856  x857  x862  x866  x869  x870  x873  x875  x876  x878  x879  x880 
#>   852   856   857   862   866   869   870   873   875   876   878   879   880 
#>  x884  x886  x888  x889  x890  x892  x897  x899  x900  x904  x905  x906  x908 
#>   884   886   888   889   890   892   897   899   900   904   905   906   908 
#>  x909  x910  x912  x913  x914  x915  x916  x917  x918  x920  x921  x925  x926 
#>   909   910   912   913   914   915   916   917   918   920   921   925   926 
#>  x928  x929  x930  x931  x935  x937  x938  x939  x942  x944  x945  x946  x947 
#>   928   929   930   931   935   937   938   939   942   944   945   946   947 
#>  x951  x952  x953  x954  x956  x959  x961  x962  x968  x972  x975  x976  x980 
#>   951   952   953   954   956   959   961   962   968   972   975   976   980 
#>  x981  x985  x986  x987  x989  x990  x991  x992  x993  x994  x995  x996  x997 
#>   981   985   986   987   989   990   991   992   993   994   995   996   997 
#>  x998 x1000 x1001 x1003 x1005 x1006 x1008 x1010 x1011 x1016 x1020 x1021 x1023 
#>   998  1000  1001  1003  1005  1006  1008  1010  1011  1016  1020  1021  1023 
#> x1027 x1028 x1036 x1037 x1039 x1040 x1043 x1044 x1049 x1050 x1053 x1054 x1056 
#>  1027  1028  1036  1037  1039  1040  1043  1044  1049  1050  1053  1054  1056 
#> x1062 x1065 x1066 x1067 x1068 x1072 x1073 x1076 x1080 x1081 x1082 x1085 x1086 
#>  1062  1065  1066  1067  1068  1072  1073  1076  1080  1081  1082  1085  1086 
#> x1087 x1089 x1091 x1092 x1093 x1094 
#>  1087  1089  1091  1092  1093  1094 

cpts <- segment(DataCPSim, method = "wbs")
changepoints(cpts$segmenter)
#>  [1]  547  822  939  972  980  982  997  999 1031 1032 1040 1041 1063 1066