Skip to contents

Create objects from periodic time series classes.

Usage

pcts(x, nseasons, start, ..., keep = FALSE)

Arguments

x

a time series.

nseasons

number of seasons. This argument is ignored by some methods.

start

the starting time of the time series, can be a (cycle, season) pair or any object that can be converted to datetime.

keep

if TRUE and x is from class "ts", "mts", "zoo", or "zooreg", create a periodic object inheriting from that class.

...

further arguments to be passed on to methods.

Details

pcts creates periodic time series objects inheriting from "PeriodicTimeSeries". The particular class depends on arguments x and, in some cases, keep. The idea is that in normal use the user does not care about the particular class. See section ‘Methods’ for further details.

There are also methods for as for conversion to and from the time series classes defined in package pcts.

Value

an object inheriting from "PeriodicTimeSeries", the defaults are "PeriodicTS" for univariate and "PeriodicMTS" and for multivariate time series.

Author

Georgi N. Boshnakov

Methods

signature(x = "numeric", nseasons = "missing")

signature(x = "numeric", nseasons = "numeric")

signature(x = "numeric", nseasons = "BasicCycle")

Creates an object of class "PeriodicTS", the native class for univariate periodic time series in package "pcts".

signature(x = "matrix", nseasons = "missing")

signature(x = "matrix", nseasons = "numeric")

signature(x = "matrix", nseasons = "BasicCycle")

Creates an object of class "PeriodicMTS", the native class for multivariate periodic time series in package "pcts".

signature(x = "data.frame", nseasons = "ANY")

Currently this just converts x to matrix and calls pcts recursively. See the methods with x = "matrix" in the signature.

signature(x = "ts", nseasons = "missing")

signature(x = "ts", nseasons = "numeric")

If keep = TRUE creates an object of class "PeriodicTS_ts", otherwise the result is from "PeriodicTS". The number of seasons is taken from the "mts" object.

signature(x = "mts", nseasons = "missing")

signature(x = "mts", nseasons = "numeric")

If keep = TRUE creates an object of class "PeriodicMTS_ts", otherwise the result is from "PeriodicMTS". The number of seasons is taken from the "ts" object.

signature(x = "xtsORzoo", nseasons = "missing")

x needs to be a regular time series, possibly with missing values for some times (technically, zoo::is.regular(x) should give TRUE). For daily time series, the cycle is taken to be day of week or a subcycle of it, most commonly Monday-Friday. The implementation of this method is incomplete but for daily data should work as described.

See also

PeriodicTS, PeriodicMTS,

dataFranses1996 for further examples

Examples

## convert a ts object, no need for further info
pcts(AirPassengers, 12)
#> An object of class "PeriodicTS"
#> Slot "cycle": Start:  1949   January 
#> Cycle:  MonthYearCycle 
#> Number of seasons: 12 
#> 
#>       Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#> Y1949 112 118 132 129 121 135 148 148 136 119 104 118
#> Y1950 115 126 141 135 125 149 170 170 158 133 114 140
#> Y1951 145 150 178 163 172 178 199 199 184 162 146 166
#> Y1952 171 180 193 181 183 218 230 242 209 191 172 194
#> Y1953 196 196 236 235 229 243 264 272 237 211 180 201
#> Y1954 204 188 235 227 234 264 302 293 259 229 203 229
#> Y1955 242 233 267 269 270 315 364 347 312 274 237 278
#> Y1956 284 277 317 313 318 374 413 405 355 306 271 306
#> Y1957 315 301 356 348 355 422 465 467 404 347 305 336
#> Y1958 340 318 362 348 363 435 491 505 404 359 310 337
#> Y1959 360 342 406 396 420 472 548 559 463 407 362 405
#> Y1960 417 391 419 461 472 535 622 606 508 461 390 432

## numeric
v24 <- rnorm(24)
pcts(v24, nseasons = 4)          # generic seasons
#> An object of class "PeriodicTS"
#> Slot "cycle": Start:  1   Season_1 
#> Cycle:  SimpleCycle 
#> Number of seasons: 4 
#> 
#>            S1         S2          S3          S4
#> C1 -1.5083427 -1.4884361  0.05775262  0.62175028
#> C2  1.7438597 -1.3140566  0.18595510 -0.06824536
#> C3 -1.6101031  0.6300192  0.50235805 -0.57740109
#> C4  0.6509080  0.9526483  0.56817663 -0.01425659
#> C5 -0.9790117  0.3182775  0.42862311  0.40308890
#> C6 -0.6631246 -1.5719161 -0.08299631 -0.19889131
pcts(v24, nseasons = BuiltinCycle(4)) # Quarter/Year
#> An object of class "PeriodicTS"
#> Slot "cycle": Start:  1   Quarter_1 
#> Cycle:  QuarterYearCycle 
#> Number of seasons: 4 
#> 
#>            Q1         Q2          Q3          Q4
#> Y1 -1.5083427 -1.4884361  0.05775262  0.62175028
#> Y2  1.7438597 -1.3140566  0.18595510 -0.06824536
#> Y3 -1.6101031  0.6300192  0.50235805 -0.57740109
#> Y4  0.6509080  0.9526483  0.56817663 -0.01425659
#> Y5 -0.9790117  0.3182775  0.42862311  0.40308890
#> Y6 -0.6631246 -1.5719161 -0.08299631 -0.19889131
ts1 <- pcts(v24, nseasons = BuiltinCycle(4), c(2006, 1)) # Quarter/Year with dates

## select subset of the seasons
window(ts1, seasons = 3:4)
#> An object of class "PeriodicTS"
#> Slot "cycle": Start:  2006   Quarter_3 
#> Cycle:  PartialCycle 
#> Number of seasons: 2 
#> 
#>                Q3          Q4
#> Y2006  0.05775262  0.62175028
#> Y2007  0.18595510 -0.06824536
#> Y2008  0.50235805 -0.57740109
#> Y2009  0.56817663 -0.01425659
#> Y2010  0.42862311  0.40308890
#> Y2011 -0.08299631 -0.19889131

## matrix, multivariate pcts
m24 <- matrix(v24, ncol =3)
colnames(m24) <- c("A", "B", "C")
pcts(m24, nseasons = 4)          # generic seasons
#> An object of class "PeriodicMTS"
#> Slot "cycle": Object from class 'SimpleCycle'
#> Number of seasons: 4 
#> Seasons: Season_1 Season_2 Season_3 Season_4 
#> Abbreviated: S1 S2 S3 S4 
#> 
#>                A           B           C
#> C1_1 -1.50834271 -1.61010312 -0.97901167
#> C1_2 -1.48843610  0.63001916  0.31827753
#> C1_3  0.05775262  0.50235805  0.42862311
#> C1_4  0.62175028 -0.57740109  0.40308890
#> C2_1  1.74385972  0.65090799 -0.66312465
#> C2_2 -1.31405662  0.95264830 -1.57191607
#> C2_3  0.18595510  0.56817663 -0.08299631
#> C2_4 -0.06824536 -0.01425659 -0.19889131
pcts(m24, nseasons = BuiltinCycle(4)) # Quarter/Year
#> An object of class "PeriodicMTS"
#> Slot "cycle": Object from built-in class 'QuarterYearCycle'
#> Cycle start: Quarter_1 
#> 
#>                A           B           C
#> Y1_1 -1.50834271 -1.61010312 -0.97901167
#> Y1_2 -1.48843610  0.63001916  0.31827753
#> Y1_3  0.05775262  0.50235805  0.42862311
#> Y1_4  0.62175028 -0.57740109  0.40308890
#> Y2_1  1.74385972  0.65090799 -0.66312465
#> Y2_2 -1.31405662  0.95264830 -1.57191607
#> Y2_3  0.18595510  0.56817663 -0.08299631
#> Y2_4 -0.06824536 -0.01425659 -0.19889131
mts1 <- pcts(m24, nseasons = BuiltinCycle(4), c(2006, 1)) # Quarter/Year with dates
mts1
#> An object of class "PeriodicMTS"
#> Slot "cycle": Object from built-in class 'QuarterYearCycle'
#> Cycle start: Quarter_1 
#> 
#>                   A           B           C
#> Y2006_1 -1.50834271 -1.61010312 -0.97901167
#> Y2006_2 -1.48843610  0.63001916  0.31827753
#> Y2006_3  0.05775262  0.50235805  0.42862311
#> Y2006_4  0.62175028 -0.57740109  0.40308890
#> Y2007_1  1.74385972  0.65090799 -0.66312465
#> Y2007_2 -1.31405662  0.95264830 -1.57191607
#> Y2007_3  0.18595510  0.56817663 -0.08299631
#> Y2007_4 -0.06824536 -0.01425659 -0.19889131

## select subset of the seasons for mutivariate
window(mts1, seasons = 3:4)
#> An object of class "PeriodicMTS"
#> Slot "cycle": Object from class 'PartialCycle'
#>     partial cycle of 'QuarterYearCycle', seasons: 3, 4
#> Cycle start: Quarter_3 
#> 
#>                   A           B           C
#> Y2006_1  0.05775262  0.50235805  0.42862311
#> Y2006_2  0.62175028 -0.57740109  0.40308890
#> Y2007_1  0.18595510  0.56817663 -0.08299631
#> Y2007_2 -0.06824536 -0.01425659 -0.19889131