…{r} setwd(“E:/cuong_dataR/test”) tute1 = read.csv(“tute1.csv”, header = T) attach(tute1) head(tute1) names(tute1) View(tute1) library(forecast) mytimeseries = ts(tute1[ ,-1], start = 1981, frequency = 4) autoplot(mytimeseries, facets = T) autoplot(mytimeseries) library(ggfortify) autoplot(mytimeseries, facets = T) autoplot(mytimeseries, facets = F) library(fpp2) retaildata = readxl::read_excel(“retail.xlsx”, skip = 1) head(retaildata) attach(retaildata) myts <- ts(retaildata[,“A3349873A”],frequency=12, start=c(1982,4)) autoplot(myts); ggseasonplot(myts); ggsubseriesplot(myts); gglagplot(myts); ggAcf(myts) help(bicoal) tsdisplay(bicoal) help(usdeaths) plot(usdeaths) seasonplot(usdeaths) tsdisplay(usdeaths) head(usdeaths) ts.usdeaths = ts(usdeaths, start = c(1973,1), frequency = 12) plot(ts.usdeaths) plot(diff(ts.usdeaths), ylab=“Differenced Tractor Deaths”) plot(log10(ts.usdeaths), ylab = “Log (Tractor Deaths)”) plot(diff(log10(ts.usdeaths)), ylab = “Log (Tractor Deaths)”) par(mfrow = c(1,2)) acf(ts(diff(log10(ts.usdeaths))),main=“ACF Tractor Deaths”) pacf(ts(diff(log10(ts.usdeaths))),main=“PACF Tractor Deaths”) library(forecast) fit = auto.arima(log10(ts.usdeaths), approximation=F, trace=F) summary(fit) pred = predict(fit, n.ahead = 36) pred par(mfrow = c(1,1)) plot(ts.usdeaths, type=‘l’, xlim=c(1973,1983), ylim=c(5000,12000),xlab=‘Year’,ylab=‘Tractor Deaths’) lines(10^(pred\(pred),col='blue') lines(10^(pred\)pred+2pred\(se),col='orange') lines(10^(pred\)pred-2pred\(se),col='orange') par(mfrow=c(1,2)) acf(ts(fit\)residuals), main=‘ACF Residual’) pacf(ts(fit$residuals), main=‘PACF Residual’)
…