Import libraries
library(tseries)
library(astsa) library(TSA)
Import Data
Sales = c(1,3,6,4,2,2,7,5,2,4,8,5,1,3,8,6) Beer_ts <- ts(Sales, start = c(2016,1), frequency = 4, end=c(2019,4))
Check data if it is a time series.
ts.plot(Beer_ts, col="blue" ,main="Beer Sales in past 4 years", xlab="Years", ylab="Sales", type="b")

ACF and PACF calculation
acf2(Beer_ts)

## [,1] [,2] [,3] [,4] [,5] [,6] ## ACF 0.09 -0.72 -0.05 0.66 0.07 -0.52 ## PACF 0.09 -0.73 0.27 0.23 -0.07 0.09
It is observed that the time series is not stationary and that there is seasonality with an upward trend. Then the trend is displayed by Decompose our data.
decomp_data = decompose (Beer_ts, type = "multiplicative")
plot (decomp_data)

plot (decomp_data$trend)

Knowing that the time series has a frequency of 4 to eliminate seasonality we get the 4 differences. Then we eliminate the trend by taking the first difference after we have taken the 4.
diff4 = diff(Beer_ts, 4)
plot.ts(diff4)

diff1and4 = diff(diff4,1)
plot.ts(diff1and4)

ACF and PACF are recalculated.
acf2(diff1and4)

## [,1] [,2] [,3] [,4] [,5] [,6] ## ACF -0.28 -0.17 0.17 -0.39 0.06 0.06 ## PACF -0.28 -0.26 0.04 -0.42 -0.21 -0.26