############################

# Author: Joshua M. Tebbs  #

# Date: 20 Dec 2009        #

# Update: 25 Jul 2011      #

# Purpose: STAT 520 R code #

# CHAPTER 1                #

############################

 

# Example 1.1.

# Page 2

globaltemps <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\globaltemps.txt"),start=1856)

plot(globaltemps,ylab="Global temperature deviations",xlab="Year",type="o")

 

# Example 1.2.

# Page 3

data(milk)

plot(milk,ylab="Amount of milk produced",xlab="Year",type="o")

 

# Example 1.3.

# Page 4

data(CREF)

plot(CREF,ylab="CREF stock values",type="o")

 

# Example 1.4.

# Page 5

homeruns <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\homeruns.txt"),start=1909)

plot(homeruns,ylab="Number of homeruns",xlab="Year",type="o")

 

# Example 1.5.

# Page 6

earthquake <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\earthquake.txt"),start=1900)

plot(earthquake,ylab="Number of earthquakes (7.0 or greater)",xlab="Year",type="o")

 

# Example 1.6.

# Page 7

enrollment <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\enrollment.txt"),start=1954)

plot(enrollment,ylab="USC Columbia fall enrollment",xlab="Year",type="o")

 

# Example 1.7.

# Page 8

data(star)

plot(star,ylab="Star brightness",type="o")

 

# Example 1.8.

# Page 9

data(airmiles)

plot(airmiles,ylab="Airline miles",xlab="Year",type="o")

 

# Example 1.9.

# Page 10

sp500 <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\sp500.txt"))

plot(sp500,ylab="SP500 Index",xlab="Time",type="o")

 

# Example 1.10.

# Page 11

ventilation <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\ventilation.txt"))

plot(ventilation,ylab="Ventilation (L/min)",xlab="Observation time",type="o")

 

# Example 1.11.

# Page 12

exchangerate <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\exchangerate.txt"),start=1980,frequency=52)

plot(exchangerate,ylab="British pounds",xlab="Year",type="o")

 

# Example 1.12.

# Page 13

data(oil.price)

plot(oil.price,ylab="Oil prices",xlab="Year",type="o")

 

# Example 1.13.

# Page 14

data(larain)

plot(larain,ylab="LA rainfall amounts",xlab="Year",type="o")

 

# Example 1.14.

# Page 15

brick <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\brick.txt"),start=1956,freq=4)

plot(brick,ylab="Australian clay brick production (in millions)",xlab="Time",type="o")

 

# Example 1.15.

# Page 16

supremecourt <- ts(read.table(file = "C:\\Users\\Tebbs\\My Documents\\texfiles\\Classes\\USC\\stat520\\f11\\data\\supremecourt.txt"),start=1926)

plot(supremecourt,ylab="Percentage granted review",xlab="Time",type="o")

 

# Example 1.8.

# Add special plotting symbols for months

# Page 19

data(airmiles)

plot(airmiles,ylab="Airline miles",xlab="Year",type='l')

points(y=airmiles,x=time(airmiles),pch=as.vector(season(airmiles)),cex=1)