library(TSstudio)
data("USgas")
ts_plot(USgas)
data("EURO_Brent")
ts_plot(EURO_Brent)
data("USVSales")
ts_plot(USVSales)
# -------- Code Chank 2 --------
acf(USgas, lag.max = 60)

# -------- Code Chank 3 --------
acf(EURO_Brent, lag.max = 60)

# -------- Code Chank 4 --------
acf(USVSales, lag.max = 60)

# -------- Code Chank 5 --------
pacf(USgas, lag.max = 60)

ts_lags(USgas)
ts_lags(USgas, lags = c(12, 24, 36, 48))
ts_lags(EURO_Brent)
ts_lags(USVSales)
data(USUnRate)
ts_plot(USUnRate, title = "US Monthly Civilian Unemployment Rate",
Ytitle = "Unemployment Rate (%)", Xtitle = "Year")
us_vsales <- window(USVSales, start = c(1976,1), end = c(2018,6))
us_unrate <- window(USUnRate, start = c(1976,1), end = c(2018,6))
# 可视化两者之间的相关性
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_ly(x = time(us_vsales), y = us_vsales, type = "scatter", mode = "line",name = "Total Vehicle Sales") %>%
add_lines(x = time(us_unrate), y = us_unrate, name = "Unemployment Rate", yaxis = "y2") %>%
layout(
title = "Total Monthly Vehicle Sales vs Unemployment Rate in the US",
yaxis2 = list( overlaying = "y", side = "right", title = "Percentage", showgrid = FALSE ),
yaxis = list(title = "Thousands of Units", showgrid = FALSE),
legend = list(orientation = 'h'), margin = list(l = 50, r = 50, b = 50, t = 50, pad = 2)
)
library(stats)
#1)可视化两个时序之间的关系
#2)measure the level of correlation between the unemployment rate and the vehicle sales and its lags using the ccf function
ccf(x = us_vsales, y = us_unrate, lag.max = 36)

library(TSstudio)
#Each bar in the CCF plot represents the level of correlation between the main series and the lags of the secondary.
#Lag 0 represents the direct correlation between the two series
ccf_plot(x = USVSales, y = USUnRate, lags = 0:12)