0% found this document useful (0 votes)
87 views19 pages

Time Series: Johnson & Johnson Quarterly Earnings Per Share, 84 Quarters, 1960 I To 1980 IV

This document contains summaries of several time series datasets: 1) It analyzes quarterly earnings per share data for Johnson & Johnson from 1960-1980. 2) It examines yearly average global temperature deviations from 1880-2015. 3) It plots and analyzes a speech recording sampled at 10,000 points per second.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views19 pages

Time Series: Johnson & Johnson Quarterly Earnings Per Share, 84 Quarters, 1960 I To 1980 IV

This document contains summaries of several time series datasets: 1) It analyzes quarterly earnings per share data for Johnson & Johnson from 1960-1980. 2) It examines yearly average global temperature deviations from 1880-2015. 3) It plots and analyzes a speech recording sampled at 10,000 points per second.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Time Series

library(astsa) # SEE THE FOOTNOTE


head(jj)

## [1] 0.71 0.63 0.85 0.44 0.61 0.69

plot(jj, type="o",
ylab="Quarterly Earnings per Share",
main="Johnson & Johnson quarterly earnings per share,
\n84 quarters, 1960-I to 1980-IV.")
grid()

Johnson & Johnson quarterly earnings per share,

84 quarters, 1960−I to 1980−IV.


15
Quarterly Earnings per Share

10
5
0

1960 1965 1970 1975 1980

Time

head(globtemp)

## [1] -0.20 -0.11 -0.10 -0.20 -0.28 -0.31

1
plot(globtemp, type="o",
ylab="Global Temperature Deviations",
main="Yearly average global temperature deviations
\n(1880–2015) in degrees centigrade.")
grid()

Yearly average global temperature deviations

(1880–2015) in degrees centigrade.


0.8
Global Temperature Deviations

0.4
0.0
−0.4

1880 1900 1920 1940 1960 1980 2000 2020

Time

head(speech)

## [1] 1814 1556 1442 1416 1352 1154

plot(speech,
main="Speech recording of the syllable aaa hhh
\nsampled at 10,000 points per second
with n = 1020 points.")
grid()

# library(TTR)
# djia = getYahooData("ˆDJI", start=20060420, end=20160420, freq="daily")
library(xts)

## Loading required package: zoo

##
## Attaching package: ’zoo’

2
## The following objects are masked from ’package:base’:
##
## as.Date, as.Date.numeric

Speech recording of the syllable aaa hhh

sampled at 10,000 points per second


with n = 1020 points.
4000
3000
speech

2000
1000
0

0 200 400 600 800 1000

Time

djiar = diff(log(djia$Close))[-1] # approximate returns


head(djiar,10)

## Close
## 2006-04-21 0.0004019814
## 2006-04-24 -0.0009813081
## 2006-04-25 -0.0046924330
## 2006-04-26 0.0062939559
## 2006-04-27 0.0024646652
## 2006-04-28 -0.0013512402
## 2006-05-01 -0.0021003229
## 2006-05-02 0.0064289317
## 2006-05-03 -0.0014173744
## 2006-05-04 0.0033784210

plot(djiar, main="DJIA Returns", type="n")

3
DJIA Returns 2006−04−21 / 2016−04−20

0.10 0.10

0.05 0.05

0.00 0.00

−0.05 −0.05

Apr 21 2006 Apr 01 2008 Apr 01 2010 Apr 02 2012 Apr 01 2014 Mar 31 2016

lines(djiar)

4
DJIA Returns 2006−04−21 / 2016−04−20

0.10 0.10

0.05 0.05

0.00 0.00

−0.05 −0.05

Apr 21 2006 Apr 01 2008 Apr 01 2010 Apr 02 2012 Apr 01 2014 Mar 31 2016

#par(mfrow = c(2,1)) # set up the graphics


head(soi,10)

## [1] 0.377 0.246 0.311 0.104 -0.016 0.235 0.137 0.191 -0.016 0.290

plot(soi, ylab="", xlab="",


main="Southern Oscillation Index")
grid()

5
Southern Oscillation Index
1.0
0.5
0.0
−0.5
−1.0

1950 1960 1970 1980

head(rec,10)

## [1] 68.63 68.63 68.63 68.63 68.63 68.63 59.16 48.70 47.54 50.91

plot(rec, ylab="", xlab="",


main="Recruitment")
grid()

6
Recruitment
100
80
60
40
20
0

1950 1960 1970 1980

#par(mfrow=c(2,1))
head(fmri1)

## time cort1 cort2 cort3 cort4 thal1 thal2 cere1 cere2


## [1,] 1 -0.336 -0.088 -0.579 -0.221 -0.222 -0.046 -0.354 -0.028
## [2,] 2 -0.192 -0.359 -0.475 -0.058 0.072 -0.039 -0.346 -0.032
## [3,] 3 0.062 0.062 0.063 0.192 0.145 -0.256 -0.337 0.272
## [4,] 4 0.128 0.221 0.234 -0.004 -0.104 -0.030 0.149 0.042
## [5,] 5 0.358 0.199 0.388 0.255 0.035 -0.081 0.311 -0.080
## [6,] 6 0.342 0.054 0.377 0.430 -0.005 0.047 0.403 -0.016

ts.plot(fmri1[,2:5], col=1:4,
ylab="BOLD", main="Cortex")
grid()

7
Cortex
0.2 0.4 0.6
BOLD

−0.2
−0.6

0 20 40 60 80 100 120

Time

ts.plot(fmri1[,6:9], col=1:4,
ylab="BOLD", main="Thalamus & Cerebellum")
grid()

8
Thalamus & Cerebellum
0.6
0.4
0.2
BOLD

−0.2 0.0
−0.6

0 20 40 60 80 100 120

Time

#par(mfrow=c(2,1))
head(EQ5)

## [1] 0.017493160 0.011390780 0.015123990 0.014765020 0.006508857


## [6] -0.002321631

plot(EQ5, main="Earthquake")
grid()

9
Earthquake
0.4
0.2
EQ5

0.0
−0.4 −0.2

0 500 1000 1500 2000

Time

head(EXP6)

## [1] -0.0018374320 -0.0005537868 -0.0022838710 -0.0003026128 -0.0007212162


## [6] -0.0013909340

plot(EXP6, main="Explosion")
grid()

10
Explosion
0.4
0.2
EXP6

0.0
−0.4 −0.2

0 500 1000 1500 2000

Time

w = rnorm(500,0,1) # 500 N(0,1) variates


head(w)

## [1] -1.0847192 -0.3184344 -0.2262302 -1.3686771 0.2253452 1.0836716

v = filter(w, sides=2, filter=rep(1/3,3)) # moving average


head(v)

## [1] NA -0.54312792 -0.63778055 -0.45652068 -0.01988675 0.65850431

#par(mfrow=c(2,1))
plot.ts(w, main="white noise")
grid()

11
white noise
3
2
1
0
w

−1
−2
−3
−4

0 100 200 300 400 500

Time

plot.ts(v, ylim=c(-3,3), main="moving average")


grid()

12
moving average
3
2
1
0
v

−1
−2
−3

0 100 200 300 400 500

Time

w = rnorm(550,0,1) # 50 extra to avoid startup problems


x = filter(w, filter=c(1,-.9), method="recursive")[-(1:50)] # remove first 50
head(x)

## [1] -3.078438 -1.027532 2.741056 2.817851 0.199729 -2.909757

plot.ts(x, main="autoregression")
grid()

13
autoregression
5
x

0
−5

0 100 200 300 400 500

Time

set.seed(154) # so you can reproduce the results


w = rnorm(200); x = cumsum(w) # two commands in one line
wd = w +.2; xd = cumsum(wd)

head(xd)

## [1] 0.7571713 -0.9523126 0.4508667 1.6257095 1.4525121 1.6911212

plot.ts(xd, ylim=c(-5,55), main="random walk", ylab='')


lines(x, col=4); abline(h=0, col=4, lty=2); abline(a=0, b=.2, lty=2)
grid()

14
random walk
50
40
30
20
10
0

0 50 100 150 200

Time

cs = 2*cos(2*pi*1:500/50 + .6*pi); w = rnorm(500,0,1)


#par(mfrow=c(3,1), mar=c(3,2,2,1), cex.main=1.5)

head(cs)

## [1] -0.8515586 -1.0716536 -1.2748480 -1.4579373 -1.6180340 -1.7526134

plot.ts(cs, main=expression(2*cos(2*pi*t/50+.6*pi)))
grid()

15
2cos(2πt 50 + 0.6π)
2
1
cs

0
−1
−2

0 100 200 300 400 500

Time

head(cs+w)

## [1] -1.0211419 -0.2238271 -0.1746897 -1.6798386 -0.9590438 -3.0467623

plot.ts(cs+w, main=expression(2*cos(2*pi*t/50+.6*pi) + N(0,1)))


grid()

16
2cos(2πt 50 + 0.6π) + N(0, 1)
4
2
cs + w

0
−2
−4

0 100 200 300 400 500

Time

head(cs+5*w)

## [1] -1.699475 3.167479 4.225944 -2.567444 1.676917 -8.223358

plot.ts(cs+5*w, main=expression(2*cos(2*pi*t/50+.6*pi) + N(0,25)))


grid()

17
2cos(2πt 50 + 0.6π) + N(0, 25)
15
10
cs + 5 * w

5
0
−5
−15

0 100 200 300 400 500

Time

x = rnorm(100)
y = lag(x, -5) + rnorm(100)
head(y)

## [1] -0.4961779 -0.6146974 -0.2836705 -2.0157873 -2.5087231 1.5612196

ccf(y, x, ylab='CCovF', type='covariance')

18
y&x
1.0
0.6
CCovF

0.2
−0.2

−15 −10 −5 0 5 10 15

Lag

19

You might also like