percentChange(obj, ...)
## S3 method for class 'default':
percentChange(obj, base=NULL, lag=1, cumulate=FALSE, e=FALSE, ...) ytoypc(obj, names = paste("y to y %ch", seriesNames(obj)))
## S3 method for class 'default':
ytoypc(obj, names = paste("y to y \%ch", seriesNames(obj)))
annualizedGrowth(obj, ...)
## S3 method for class 'default':
annualizedGrowth(obj, lag=1, freqLagRatio=frequency(obj)/lag,
names=paste("Annual Growth of", seriesNames(obj)), ...)
obj
's frequency to the number of lags.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.
diff
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