Calculate various conversions of time series.
percentChange(obj, ...)
# S3 method for default
percentChange(obj, base=NULL, lag=1, cumulate=FALSE, e=FALSE, ...) ytoypc(obj, names = paste("y to y %ch", seriesNames(obj)))
# S3 method for default
ytoypc(obj, names = paste("y to y %ch", seriesNames(obj)))
annualizedGrowth(obj, ...)
# S3 method for default
annualizedGrowth(obj, lag=1, freqLagRatio=frequency(obj)/lag,
names=paste("Annual Growth of", seriesNames(obj)), ...)
An object on which the calculation is to be done. The default method works for a time series vector or matrix (with columns corresponding to series, which are treated individually).
If e is TRUE the exponent of the series is used (after cumulating if cumulate is TRUE). e can be a logical vector with elements corresponding to columns of obj.
If base is provided it is treated as the first period value (that is, prior to differencing). It is prefixed to the m prior to cumulating. It should be a vector of length dim(m)[2]. (If e is TRUE then base should be log of the original data).
integer indicating the number of periods relative to which the change should be calculated.
logical indicating if the series should be cumulated before the percent change is calculated.
the ratio of obj
's frequency to the number of lags.
gives new names to be given to the calculated series.
arguments passed to other methods.
A time series or time series matrix.
percentChange
calculate the percent change relative to the data lag periods prior.
If cumulate
is TRUE then the data is cumulated first. cumulate
can be
a logical vector with elements corresponding to columns of obj.
The result is a time series of the year over year percent change. This uses percentChange with lag=frequency(obj).
The names
are not applied to the new series if the global option
ModSeriesNames is FALSE. This can be set
with options(ModSeriesNames=FALSE)
. This provides a convenient
mechanism to prevent changing series labels on plot axis, when the title
may indicate that data is in year-to-year percent change so the axis label
does not need this.
annualizedGrowth
calculates the year to year percentage growth rate using
100*((obj/shift(obj, periods= -lag))^freqLagRatio - 1)
. The default
gives the annualized one period growth. If lag
is equal to the frequency of obj
then the result is year-over-year
growth.
# NOT RUN {
z <- ts(matrix(100 + rnorm(200),100,2), start=c(1990,1), frequency=12)
z[z == 0] <- 1 # not to likely, but it can happen
zyypc <- ytoypc(z)
zpc <- percentChange(z)
zag <- annualizedGrowth(z)
# }
Run the code above in your browser using DataLab