Complete R code

The following is the complete R code:

# Time series datakings <- scan("http://robjhyndman.com/tsdldata/misc/kings.dat",skip=3)king.ts <- ts(kings)king.tsinstall.packages("TTR")library(TTR)par(mfrow=c(2 ,2))plot(SMA(king.ts, n=2), main = "n=2")plot(SMA(king.ts, n=5), main = "n=5")plot(SMA(king.ts, n=10), main = "n=10")plot(SMA(king.ts, n=15), main = "n=15")par(mfrow=c(1,1))smooth.king <- SMA(king.ts, n=5)smooth.kingbirths <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")births.ts <- ts(births, frequency = 12)births.comps <- decompose(births.ts)plot(births.comps)library(zoo)library(quantmod)data <- as.zoo(smooth.king)x1 <- Lag(data,1)new.data <- na.omit(data.frame(Lag.1 = x1, y = data))head(new.data)model <- lm(y ...

Get R Data Analysis Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.