Problem Set 1
#Problem 1.2
s <- c(rep(0,100), 10*exp(-(1:100)/20)*cos(2*pi*1:100/4))
xa <- ts(s +rnorm(200,0,1))
plot(xa)

s = c(rep(0,100), 10*exp(-(1:100)/200)*cos(2*pi*1:100/4))
xb <- ts(s +rnorm(200,0,1))
plot(xb)

plot(cbind(xa,xb))

#PROBLEM 1.3
w = rnorm(100, 0,1)
x <- filter(w, filter = c(0,-.9), method="recursive")
v = filter(x, rep(1/4,4), sides = 1)
w2 = cos((2*pi*1:100)/4)
v2 = filter(w2, rep(1/4,4), sides = 1)
w3 = cos((2*pi*1:100)/4) + w
v3 = filter(w3, rep(1/4,4), sides = 1)
par(mfcol=c(3,1))
plot(cbind(x, v), plot.type="single", lty=1:2)
plot(cbind(w2, v2),plot.type="single", lty=1:2)
plot(cbind(w3, v3),plot.type="single", lty=1:2)

#1.5
s1 <- c(rep(0,100), 10*exp(-(1:100)/20)*cos(2*pi*1:100/4))
x1 <- ts(s1 + rnorm(200, 0, 1))
ts.plot(x1)
abline(h=mean(x1), col="purple")
acf(x1)
s1 <- c(rep(0,100), 10*exp(-(1:100)/200)*cos(2*pi*1:100/4))
x1 <- ts(s1 + rnorm(200, 0, 1))
plot(x1)
abline(h=mean(x1), col="red")

acf(x1)
#1.20
w5 <- rnorm(5000,0,1)
acf(w5,20)
w50<- rnorm(50,0,1)
acf(w50,20)

#more obsetvations the smaler the CI becomes. Less variance
#1.21
w<- rnorm(500,0,1)
v<- filter(w, sides=2, filter = rep(1/3,3))
acf(v[2:499],20)
#sin Shaped
#1.23
cs <- 2*cos(2*pi*1:500/50 +.6*pi)
w <- rnorm(500,0,1)
acf(cs+w,100)
#sin graph smaller velocity
