Difference between revisions of "R TimeSeries"
Line 7: | Line 7: | ||
library(forecast) | library(forecast) | ||
− | to your code | + | to your code. |
== Importing Data == | == Importing Data == | ||
+ | |||
+ | Here we will initially use a dataset on UK CPI [[media:UKCPI.xls|UKCPI.xls]]. Doenload this and save it as a csv file as this will facilitate the upload to R. | ||
+ | |||
+ | setwd("YOUR DIRECTORY") # This sets the working directory | ||
+ | data <- read.csv("UKCPI.csv") # Opens UKCPI.csv from working directory | ||
+ | |||
+ | which will produce a dataframe (<source>data</source>) with two variables, one giving dates (<source>DATE</source>) and the other containing the actual CPI data for 1988Q1 to 2013Q4 (<source>UKCPI</source>). | ||
+ | |||
+ | == Basic Time-Series Data Transformations == | ||
+ | |||
+ | The first thing we need is to ensure that R knows that the data we are dealing with are actually time series data. There is a function in R you can use to check that. | ||
== Additional Resources == | == Additional Resources == |
Revision as of 21:09, 11 February 2015
In this section we will demonstrate how to do basic univariate time-series modelling with R. We will use a package written by Rob Hyndman, called "forecast". So before you get started you need to go to R and
install.packages("forecast")
But note that this package requires R of version 3. Then at the beginning of your code you will have to import the library by adding
library(forecast)
to your code.
Importing Data
Here we will initially use a dataset on UK CPI UKCPI.xls. Doenload this and save it as a csv file as this will facilitate the upload to R.
setwd("YOUR DIRECTORY") # This sets the working directory data <- read.csv("UKCPI.csv") # Opens UKCPI.csv from working directorywhich will produce a dataframe (
data
DATE
UKCPI
Basic Time-Series Data Transformations
The first thing we need is to ensure that R knows that the data we are dealing with are actually time series data. There is a function in R you can use to check that.
Additional Resources
- A very quick intro from Quick-R can be found here [1]
- We are using the package "forecast" authored by Rob Hyndman who has also written an online textbook on the topic of forecasting [2]
- To access some very useful data-series in a very convenient way we will also use the QUANDL package.