1. Convert the data for Cattle, Hog, and Goat into 3 time series.
  2. Create time series plot for each of the series. What time series component (trend, seasonality, cycle, irregular) can you observe in each time series? Explain your answer.
  3. Compute lag-1 and lag-2 for each of the 3 series. Plot the lagged series and the original series in a single graph. What can you observe? What is effect of lagging, if any?
  4. Compute first- and second-differences for each of the 3 series. Plot the differenced series in a single graph. What can you observe? What is effect of differencing, if any?
  5. Compute 3-quarter and 5-quarter moving averages for each time series. Plot the moving averages together with the original series in one graph. What can you observe? What is effect of moving averages, if any?

Cattle

Time Series Plot for Cattles

cattle <- read.csv('Livestock.csv')
cattle_ts <- ts(cattle$Cattle,
             start = c(2000,1),
             end = c(2022,4),
             frequency = 4)
plot(cattle_ts,
     type="o",
     xlab="Year",
     ylab="Cattle Production",
     main="Quarterly Cattle Production: 2000-2022")

The plot has a seasonal and downward trend time series component. At a certain length of the time series there has been an observed seasonality and the direction of the trend goes down most of the time.

Lagged Series Plot

cattle.lag1a <- dplyr::lag(cattle$Cattle,n=1) 
cattle.lag2a <- dplyr::lag(cattle$Cattle,n=2)
cattle1a <- cbind(cattle$Cattle, cattle.lag1a, cattle.lag2a)
plot.ts(cbind(cattle_ts,cattle.lag1a,cattle.lag2a),
        plot.type="single",
        col=c("black", "red", "blue"))

It can be observed that the data point of the original time series has an influence to the later points of time. This will result to having a predicted value from the past values.

Difference Series Plot

cattle1<-diff(cattle_ts,lag=1)
cattle2<-diff(cattle1,lag=1) 
plot.ts(cbind(cattle1,cattle2),
        plot.type="single",
        col=c("black", "red"))

It can be observed that there is a transformation of the series and this will result to the removal of the seasonality and trend.

Moving Averages Plot

cattlema3<-ma(cattle_ts,order=3)
cattlema5<-ma(cattle_ts,order=5)

plot.ts(cbind(cattle_ts,cattlema3,cattlema5),
        plot.type = 'single',
        col=c('black', 'red', 'blue'))

It can be observed that by having the moving averages, it will eliminate variations from the original plot which emphasizes a smoother plot.

Hog

Time Series Plot for Hogs

hog <- read.csv('Livestock.csv')
hog_ts <- ts(hog$Hog,
             start = c(2000,1),
             end = c(2022,4),
             frequency = 4)
plot(hog_ts,
     type="o",
     xlab="Year",
     ylab="Hog Production",
     main="Quarterly Hog Production: 2000-2022")

There is a repeated variation in the series from the plot above which makes it a seasonalistic time series. It can also be seen that there is a downward trend. And the seasonal pattern from the plot are observed at every quarter of the year.

Lagged Series Plot

hog.lag1a <- dplyr::lag(hog$Hog,n=1) 
hog.lag2a <- dplyr::lag(hog$Hog,n=2)
hog1a <- cbind(hog$Hog, hog.lag1a, hog.lag2a)
plot.ts(cbind(hog_ts,hog.lag1a,hog.lag2a),
        plot.type="single",
        col=c("black", "red", "blue"))

It can be observed that the data point of the original time series has an influence to the later points of time. This will result to having a predicted value from the past values.

Difference Series Plot

hog1<-diff(hog_ts,lag=1)
hog2<-diff(hog1,lag=1) 
plot.ts(cbind(hog1,hog2),
        plot.type="single",
        col=c("black", "red"))

It can be observed that there is a transformation of the series and this will result to the removal of the seasonality and trend.

Moving Averages Plot

hogma3<-ma(hog_ts,order=3)
hogma5<-ma(hog_ts,order=5)

plot.ts(cbind(hog_ts,hogma3,hogma5),
        plot.type = 'single',
        col=c('black', 'red', 'blue'))

It can be observed that by having the moving averages, it eliminated variations from the original plot which emphasizes a smoother plot.

Goat

Time Series Plot for Goats

goat <- read.csv('Livestock.csv')
goat_ts <- ts(goat$Goat,
             start = c(2000,1),
             end = c(2022,4),
             frequency = 4)
plot(goat_ts,
     type="o",
     xlab="Year",
     ylab="Goat Production",
     main="Quarterly Goat Production: 2000-2022")

There is a sequence of repeated events from the plot above which makes it a cyclistic time series.

Lagged Series Plot

goat.lag1a <- dplyr::lag(goat$Goat,n=1) 
goat.lag2a <- dplyr::lag(goat$Goat,n=2)
goat1a <- cbind(goat$Goat, goat.lag1a, goat.lag2a)
plot.ts(cbind(goat_ts,goat.lag1a,goat.lag2a),
        plot.type="single",
        col=c("black", "red", "blue"))

It can be observed that the data point of the original time series has an influence to the later points of time. This will result to having a predicted value from the past values.

Difference Series Plot

goat1<-diff(goat_ts,lag=1)
goat2<-diff(goat1,lag=1) 
plot.ts(cbind(goat1,goat2),
        plot.type="single",
        col=c("black", "red"))

It can be observed that there is a transformation of the series and this resulted to the removal of the cycle.

Moving Averages Plot

goatma3<-ma(goat_ts,order=3)
goatma5<-ma(goat_ts,order=5)

plot.ts(cbind(goat_ts,goatma3,goatma5),
        plot.type = 'single',
        col=c('black', 'red', 'blue'))

It can be observed that by having the moving averages, it eliminated variations from the original plot which emphasizes a smoother plot.