Lab: Introduction to R and Time Series


Getting Started with R

Click on the R icon

To quit R:

> q()

What does it ask you? What does this mean?

For R HELP, for example to get help about the function rnorm ,

> help(rnorm)

You can also go to Help on the R toolbar and select R Help.


Example 1: Let the games begin.

Generate a sample of n=100, N(0,1) random variables.

> help(rnorm)

> rnorm(100)

What happened?

Now, let's try:

> temp <- rnorm(100)

What is in the object temp?

What is the length of the oject temp?

Make a informative plot of temp?

Q: How can you make a time series plot of the data? (The model is: Yt = et)

Let's now use the R function set.seed() to allow us to reproduce our results! Repeat the above command: ( temp <- rnorm(100) after

> set.seed(1)

Compare what is in the object temp with a neighbor. It should be exactly the same!


Example 2: The Random Walk

Let's look at the sample code in random_walk_ex.r

Q: What happens when you change (larger and smaller) the standard deviation of the noise?


Example 3: AR(1)

The model: Yt = φ1Yt-1 + et

Let's look at sample code in ar1.ex1.r

Q: What are the differences that you observe in the 4 plots and how do they compare to the Random Walk?


Text Book webpage and TSA R Package:

Let's see if we can install the TSA R package on our computers!

Let's see if we can use the TSA R package and produce the plots in Chapter 1 from: Text Book webpage


Check out more tutorials on R linked off the Course Calendar!