Time Series Objects

DESCRIPTION:
Defines a univariate or multivariate time series.

USAGE:
ts(data = NA, start = <<see below>>, frequency = 1, end = NULL,
   deltat = 1, names = <<see below>>, ts.eps  =  .Options$ts.eps)
is.ts(x)
as.ts(x)

REQUIRED ARGUMENTS:
x:
any S-PLUS object.

OPTIONAL ARGUMENTS:
data:
a vector or a matrix giving the data values for the time series. If a matrix, each column represents one series of a multivariate time series.
Missing values (NA) are allowed.
start:
starting date for the series, e.g., in years, February, 1970 would be 1970+(1/12) or 1970.083. If start is a vector with at least two data values, the first is interpreted as the time unit, e.g., the year, and the second as the number of positions into the sampling period; e.g., February, 1970 could be c(1970,2). If both start and end are missing, then start defaults to 1.
frequency:
observations frequency; that is, how many observations per sampling period. For example, monthly data have frequency=12.
end:
ending date for the series. If this is given, it and the length of data are used to compute start.
deltat:
argument to be provided instead of frequency. This represents the fraction of the sampling period between successive observations; e.g., monthly data has deltat=1/12. Only one of frequency or deltat should be provided.
names:
(only used when data is a matrix): a vector containing character strings to be used as names for the component series of the multivariate series. By default, the strings "Series i" i=1,2,..., ncol(data) are used as series names (columns of data) unless data has an associated dimnames attribute which is retained by the resulting time series. The rows of the matrix are also named using the associated times (from given start and end parameters) for the observations.
ts.eps:
time series comparison tolerance. This small number is used throughout the time series functions for comparison of their frequencies. It defaults to .Options$ts.eps=1e-5 which means that frequencies will be considered equal if they correspond up to their 5th decimal, if a fraction.

VALUE:
ts returns a time series containing the given data. Time series attributes are assigned consistently with whichever of start, end, frequency or deltat are supplied. If frequency or deltat is supplied, then only one of start or end is needed since the other parameter is computed based on the given values and length(data) (or nrow(data)). If both start and end are omitted, the series is started at 1. ts checks that the arguments supplied are consistent.

is.ts returns TRUE if x is a time series object (has a tsp attribute), and returns FALSE otherwise.

as.ts returns x, if x is a time series, otherwise ts(x).


DETAILS:
Any periodic data can be organized as a time series. Hourly data might use days for start and end with frequency=24 or deltat=1/24; daily data could use weeks with frequency=7 or deltat=1/7. There is also special printing for the cases of frequency=4 or 12 (see print.ts).

Time series objects are those that have an attribute tsp, which must be numeric of length 3. Multivariate time series objects also have attributes dim and (possibly) dimnames.

Multivariate time series are printed by default like a matrix with the tsp attribute printed last. Calling print.ts directly provides an alternative.


NOTE:
Time series created by ts have been superseded by the classed time series created by rts, cts, and its. You can coerce a old-style time series to a new with as.rts.

SEE ALSO:
print.ts , tsmatrix , tsp , tsplot .

EXAMPLES:
tsp(freeny.y)
# [1] 1962.25 1971.75 4.00

is.ts(freeny.y) # [1] T

# Define the matrix of related covariates as a time series and plot ts.freeny.x <- ts(freeny.x, start = 1962.25, frequency = 4) tsplot(ts.freeny.x, freeny.y)