140 likes | 419 Views
R Support for Time Series November 2012. Stu Rodgers. Installation and Set up. Install a version of R ( http://www.r-project.org ) http://cran.us.r-project.org/bin/windows/base/ Install and load the packages install.packages(c(“xts"),repos=c("http://cran.us.r-project.org")) library(“xts”)
E N D
R Support forTime SeriesNovember 2012 Stu Rodgers
Installation and Set up • Install a version of R (http://www.r-project.org) • http://cran.us.r-project.org/bin/windows/base/ • Install and load the packages • install.packages(c(“xts"),repos=c("http://cran.us.r-project.org")) • library(“xts”) • install.packages(c(“tseries"),repos=c("http://cran.us.r-project.org")) • library(“tseries”) • install.packages(c(“chron"),repos=c("http://cran.us.r-project.org")) • library(“chron”) • Get the package references if desired • http://cran.us.r-project.org/web/packages/tseries/tseries.pdf • http://cran.us.r-project.org/web/packages/zoo/zoo.pdf • http://cran.us.r-project.org/web/packages/xts/xts.pdf • http://cran.us.r-project.org/web/packages/chron/chron.pdf • Reference • http://cran.us.r-project.org/web/views/TimeSeries.html
Times and Dates Versus Data chron POSIXct character Time Classes Date yearqtr yearmon numeric timeDate POSIXlt fts matrix zoo ts timeSeries irts data.frame vector mts its Data Classes
ts • in package stats • regularly spaced time series • well-suited for annual, monthly, quarterly data, etc.
POSIX classes • POSIXct – seconds since the epoch • POSIXlt – list of components • sec, min, hour, mday, mon, year, wday, yday, isdat
zoo • Older classes vary in implementation • timeSeries, its, irts • restricted to particular class (1 each) for time scale • indexed by : timeDate, POSIXct • Provides more general support for ordered observations • index by : numeric, Date, POSIXct, etc • Provide methods to standard generic functions • simplify usage by conforming Z’s ordered observations, originally designed for package strucchange (Zeileis, et al)
zoo • Create a zoo object • zoo(x, order.by) • x is vector or matrix • order.by is index by which the obs should be ordered • NROW(x) must equal length(order.by) • Standard generic functions • print, summary, str, head, tail, [ (subsetting), etc.
xts • zoo object inside • Why xts? • Growth of R and the challenge of choice • Prior coercion methods failed to maintain the original object's data in its entirety • Conversion from timeSeries to zoo : loss of FinCenter, format, recordIDs attributes, e.g. • Benefit to developers and users
xts • Differences • formal time-based classes for indexing • Date, POSIXct, chron, yearmon, yearqtr, timeDate • internal xts properties • user-added attributes • other class’s specific attributes stored here during conversion
xts • Standard generic functions • [, cbind, rbind, c, str, Ops, print, na.omit, time, index, plot, coredata • Subsetting • ISO:8601 time format “CCYY-MM-DD HH:MM:SS”
Questions • Stu Rodgers • 937-903-0558 • s.rodgers@tier1performance.com • All subject content for this presentation was obtained at http://www.r-project.org