# Function plot
library(forecast)
library(plotly)
# Usefull function
source("shiny/www/customize_function.R")
# Libraries
toolbox::tidysession(select = "base")
# Data
data("USeconomic", package = "tseries")
############################### INPUT ##########################################
var.1 = c("log(M1)", "log(GNP)")
var.temp = "None"
timestamp = "Quarterly"
seasonal.adjustment = TRUE
trend = TRUE
auto.trend = TRUE
trend.order = 10
################################################################################
pl = list()
for(i in 1:length(var.1)) {
dt = USeconomic %>%
as_tibble() %>%
add_time(var.temp) %>%
select(x = var.1[i], temps) %>%
adjust_season(seasonal.adjustment, timestamp) %>%
add_trend(trend, auto.trend, trend.order, timestamp)
pl[[i]] = dt %>%
plot_ly(
x = ~ temps,
y = ~ x,
type = 'scatter',
mode = 'lines',
name = 'Realisation',
hoverinfo = 'text'
) %>%
layout(title = paste("Réalisation de la série :", var.1[i]),
yaxis = list(title = "")) %>%
add_plot_trend(trend,
auto.trend,
trend.order)
}
subplot(pl)
################################################################################
USeconomic = as_tibble(USeconomic)
var.1 = "log(M1)"
var.2 = c("log(GNP)", "rl")
for(i in 1:length(var.2)){
ets(USeconomic[,1], allow.multiplicative.trend = T) %>% plot()
}
################################################################################
var.mod = VAR(USeconomic) %>%
irf(response = "rl") # Reactive with input$var.1
me = as.data.frame(var.mod$irf)
ci_min = as.data.frame(var.mod$Lower) %>% rename_all(.funs = funs(paste0("min.", .)))
ci_max = as.data.frame(var.mod$Upper)%>% rename_all(.funs = funs(paste0("max.", .)))
irf.dt = as_tibble(cbind(me, ci_min, ci_max))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.