# 1.3 Autocovariances and Autocorrelations (Solution to Homework) # Ex 1.16 generate a time series Y_t = b0+b1*t+eps_t, for t, t = 1,..., 100, where b0 and b1 # are not equal to 0 and the eps_t are independent normal random variables with mean mu and variance sig_1^2 # if t <= 69 but variance sig_2^2 if t >= 70. Plot the exponentially filtered variables Y*_t for different # values of the smoothing parameter alpha and compare the results. b0 <- 2; b1 <- 0.05; mu <- 0; sig1 <- 1; sig2 <- 2 t <- 1:100 Y <- b0 + b1*t + rnorm(100,mu,c(rep(sig1,69),rep(sig2,100-69))) plot(Y,type="l") a1 <- 0.3; a2 <- 0.1 Ys1 <- Ys2 <- Y for(i in t[-1]) { Ys1[i] <- a1*Y[i] + (1-a1)*Ys1[i-1] Ys2[i] <- a2*Y[i] + (1-a2)*Ys2[i-1] } lines(Ys1,col="blue") lines(Ys2,col="red") # Ex 1.20: Consider the percentages to annual bancruptcies among all US companies between # 1867 and 1932. Compute and plot the empirical autocovariance function and the empirical # autocorrelation function bankrupt <- read.table("bankrupt.txt") bankrupt <- ts(bankrupt[,2],start=1867) plot(bankrupt) acf(bankrupt) acf(bankrupt,type="covariance") # Ex 1.21: Plot the correlogram for di erent values of n. t <- 1:100 acf(t) n <- 100 k <- 0:20 r <- 1 - 3*k/n + 2*k*(k^2-1)/(n*(n^2-1)) points(k,r,col="red")