R: Regular zoo Series (2024)

zooreg {zoo}R Documentation

Description

zooreg is the creator for the S3 class "zooreg"for regular "zoo" series. It inherits from "zoo"and is the analogue to ts.

Usage

zooreg(data, start = 1, end = numeric(), frequency = 1, deltat = 1, ts.eps = getOption("ts.eps"), order.by = NULL, calendar = getOption("zoo.calendar", TRUE))

Arguments

data

a numeric vector, matrix or a factor.

start

the time of the first observation. Either a single number ora vector of two integers, which specify a natural time unitand a (1-based) number of samples into the time unit.

end

the time of the last observation, specified in the same wayas start.

frequency

the number of observations per unit of time.

deltat

the fraction of the sampling period between successiveobservations; e.g., 1/12 for monthly data. Only one offrequency or deltat should be provided.

ts.eps

time series comparison tolerance. Frequencies are consideredequal if their absolute difference is less than ts.eps.

order.by

a vector by which the observations in xare ordered. If this is specified the arguments start andend are ignored and zoo(data, order.by, frequency) iscalled. See zoo for more information.

calendar

logical. Should yearqtr or yearmonbe used for a numeric time index with frequency 4 or 12, respectively?

Details

Strictly regular series are those whose time points are equally spaced.Weakly regular series are strictly regular time series in which someof the points may have been removed but still have the originalunderlying frequency associated with them."zooreg" is a subclass of "zoo" that is used to represent both weaklyand strictly regular series. Internally, it is the same as "zoo" except it also has a "frequency" attribute. Its index class is more restricted than "zoo". The index: 1. must be numeric or a class which can be coercedvia as.numeric (such as yearmon, yearqtr,Date, POSIXct, tis, xts, etc.). 2. when converted to numericmust be expressible as multiples of 1/frequency. 3.group generic functions Ops should be defined, i.e.,adding/subtracting a numeric to/from the index class should produce the correctvalue of the index class again.

zooreg is the zoo analogue to ts. The argumentsare almost identical, only in the case where order.by is specified,zoo is called with zoo(data, order.by, frequency). Itcreates a regular series of class "zooreg" which inherits from "zoo".It is essentially a "zoo" series with an additional "frequency"attribute. In the creation of "zooreg" objects (via zoo,zooreg, or coercion functions) it is always check whether theindex specified complies with the frequency specified.

The class "zooreg" offers two advantages over code "ts": 1. Theindex does not have to be plain numeric (although that is the default), it justmust be coercible to numeric, thus printing and plotting can be customized.2. This class can not only represent strictly regular series, but also serieswith an underlying regularity, i.e., where some observations from a regular gridare omitted.

Hence, "zooreg" is a bridge between "ts" and "zoo" andcan be employed to coerce back and forth between the two classes. The coercionfunction as.zoo.ts returns therefore an object of class "zooreg"inheriting from "zoo". Coercion between "zooreg" and "zoo"is also available and drops or tries to add a frequency respectively.

For checking whether a series is strictly regular or does have an underlyingregularity the generic function is.regular can be used.

Methods to standard generics for regular series such as frequency,deltat and cycle are available for both "zooreg"and "zoo" objects. In the latter case, it is checked first (in a data-driven way)whether the series is in fact regular or not.

as.zooreg.tis has a class argument whose value represents theclass of the index of the zooreg object into which the tisobject is converted. The default value is "ti". Note that the frequency of the zooreg object will not necessarily be the sameas the frequency of the tis object that it is converted from.

Value

An object of class "zooreg" which inherits from "zoo".It is essentially a "zoo" series with a "frequency"attribute.

See Also

zoo, is.regular

Examples

## equivalent specifications of a quarterly series## starting in the second quarter of 1959.zooreg(1:10, frequency = 4, start = c(1959, 2))as.zoo(ts(1:10, frequency = 4, start = c(1959, 2)))zoo(1:10, seq(1959.25, 1961.5, by = 0.25), frequency = 4)## use yearqtr class for indexing the same seriesz <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4)zz[-(3:4)]## create a regular series with a "Date" indexzooreg(1:5, start = as.Date("2000-01-01"))## or with "yearmon" indexzooreg(1:5, end = yearmon(2000))## lag and diff (as diff is defined in terms of lag)## act differently on zoo and zooreg objects!## lag.zoo moves a point to the adjacent time whereas## lag.zooreg moves a point by deltatx <- c(1, 2, 3, 6)zz <- zoo(x, x)zr <- as.zooreg(zz)lag(zz, k = -1)lag(zr, k = -1)diff(zz)diff(zr)## lag.zooreg wihtout and with na.padlag(zr, k = -1)lag(zr, k = -1, na.pad = TRUE)## standard methods available for regular seriesfrequency(z)deltat(z)cycle(z)cycle(z[-(3:4)])zz <- zoo(1:6, as.Date(c("1960-01-29", "1960-02-29", "1960-03-31", "1960-04-29", "1960-05-31", "1960-06-30")))# this converts zz to "zooreg" and then to "ts" expanding it to a daily# series which is 154 elements long, most with NAs.## Not run: length(as.ts(zz)) # 154## End(Not run)# probably a monthly "ts" series rather than a daily one was wanted.# This variation of the last line gives a result only 6 elements long.length(as.ts(aggregate(zz, as.yearmon, c))) # 6zzr <- as.zooreg(zz)dd <- as.Date(c("2000-01-01", "2000-02-01", "2000-03-01", "2000-04-01"))zrd <- as.zooreg(zoo(1:4, dd))

[Package zoo version 1.8-12 Index]

R: Regular zoo Series (2024)

References

Top Articles
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 5552

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.