Baixando as Bibliotecas
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(fpp)
## Loading required package: fma
## Loading required package: expsmooth
## Loading required package: lmtest
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: tseries
library(fpp2)
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ ggplot2 3.4.4
##
##
## Attaching package: 'fpp2'
## The following objects are masked from 'package:fpp':
##
## ausair, ausbeer, austa, austourists, debitcards, departures,
## elecequip, euretail, guinearice, oil, sunspotarea, usmelec
library(tseries)
library(patchwork)
library(xts)
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
library(zoo)
library(tibble)
library(readxl)
Converta os dados de vendas consolidadas para um objeto de série
temporal
ts_vendas <- ts(venda_consolidada$venda_mensal, frequency = 12,start = c(2017,1))
plot(ts_vendas)

Ajuste um modelo SARIMA aos dados
modelo_sarima <- auto.arima(ts_vendas)
Faça a previsão para os próximos 12 meses (1 ano)
previsao <- forecast(modelo_sarima, h = 12)
Imprima a previsão
print(previsao)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Apr 2023 640477.5 576728.0 704227.1 542981.0 737974.0
## May 2023 771324.3 692254.1 850394.5 650396.8 892251.7
## Jun 2023 756612.1 670413.6 842810.7 624782.9 888441.4
## Jul 2023 679514.9 589712.5 769317.3 542173.9 816855.9
## Aug 2023 678775.7 587091.5 770459.8 538556.9 818994.5
## Sep 2023 670983.0 578301.5 763664.5 529238.9 812727.1
## Oct 2023 758361.7 665147.6 851575.7 615803.1 900920.2
## Nov 2023 858347.9 764848.4 951847.4 715352.8 1001343.1
## Dec 2023 967997.9 874345.0 1061650.7 824768.2 1111227.5
## Jan 2024 701492.5 607757.3 795227.8 558136.8 844848.3
## Feb 2024 626551.3 532771.6 720330.9 483127.7 769974.9
## Mar 2024 697539.0 603735.4 791342.5 554078.8 840999.1
Plote a previsão
autoplot(previsao) +
autolayer(ts_vendas, series = "Vendas") +
labs(title = "Previsão de Vendas com Modelo SARIMA",
y = "Vendas",
x = "Data")

Converta os dados de vendas consolidadas para um objeto de série
temporal
ts_vendas <- ts(venda_consolidada$venda_mensal, frequency = 12,start = c(2017,1))
plot(ts_vendas)

Ajuste um modelo SARIMA aos dados
modelo_sarima <- auto.arima(ts_vendas)
Faça a previsão para os próximos 12 meses (1 ano)
previsao <- forecast(modelo_sarima, h = 12)
Imprima a previsão
print(previsao)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Apr 2023 640477.5 576728.0 704227.1 542981.0 737974.0
## May 2023 771324.3 692254.1 850394.5 650396.8 892251.7
## Jun 2023 756612.1 670413.6 842810.7 624782.9 888441.4
## Jul 2023 679514.9 589712.5 769317.3 542173.9 816855.9
## Aug 2023 678775.7 587091.5 770459.8 538556.9 818994.5
## Sep 2023 670983.0 578301.5 763664.5 529238.9 812727.1
## Oct 2023 758361.7 665147.6 851575.7 615803.1 900920.2
## Nov 2023 858347.9 764848.4 951847.4 715352.8 1001343.1
## Dec 2023 967997.9 874345.0 1061650.7 824768.2 1111227.5
## Jan 2024 701492.5 607757.3 795227.8 558136.8 844848.3
## Feb 2024 626551.3 532771.6 720330.9 483127.7 769974.9
## Mar 2024 697539.0 603735.4 791342.5 554078.8 840999.1
Plote a previsão
autoplot(previsao) +
autolayer(ts_vendas, series = "Vendas") +
labs(title = "Previsão de Vendas com Modelo SARIMA",
y = "Vendas",
x = "Data")
