knitr::opts_chunk$set(echo = TRUE)
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(readr)
library(readxl)
library(writexl)
library(openxlsx)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## ######################### 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
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(fpp3)
## Registered S3 method overwritten by 'tsibble':
## method from
## as_tibble.grouped_df dplyr
## ── Attaching packages ──────────────────────────────────────────── fpp3 1.0.1 ──
## ✔ tibble 3.2.1 ✔ tsibbledata 0.4.1
## ✔ tidyr 1.3.1 ✔ feasts 0.4.1
## ✔ ggplot2 3.5.1 ✔ fable 0.4.1
## ✔ tsibble 1.1.5
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date() masks base::date()
## ✖ dplyr::filter() masks stats::filter()
## ✖ xts::first() masks dplyr::first()
## ✖ tsibble::index() masks zoo::index()
## ✖ tsibble::intersect() masks base::intersect()
## ✖ tsibble::interval() masks lubridate::interval()
## ✖ dplyr::lag() masks stats::lag()
## ✖ xts::last() masks dplyr::last()
## ✖ tsibble::setdiff() masks base::setdiff()
## ✖ tsibble::union() masks base::union()
library(forecast)
library(AutoPlots)
library(fpp)
## Loading required package: fma
## Loading required package: expsmooth
## Loading required package: lmtest
## Loading required package: tseries
##
## Attaching package: 'fpp'
## The following object is masked from 'package:fpp3':
##
## insurance
library(mFilter)
library(xts)
library(zoo)
library(plogr)
library(patchwork)
library(tseries)
library(quantmod)
library(fpp3)
library(forecast)
library(fpp)
library(xts)
library(zoo)
library(plogr)
Vendas2024 <- read_excel("Vendas2024.xlsx")
vendas_mes <- Vendas2024 %>%
group_by(ano, mes) %>%
summarise(venda_mensal = sum(venda_diaria)) %>%
arrange(ano, mes)
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
plot(vendas_mes$venda_mensal)
vendas_mes_ts <- ts(vendas_mes$venda_mensal, start = c(2018,1), frequency = 12)
plot(vendas_mes_ts)
decomp_vendas_mes <- decompose(vendas_mes_ts, type = 'additive')
plot(decomp_vendas_mes)
forecast(vendas_mes_ts, 6, 90)
## Point Forecast Lo 90 Hi 90
## Apr 2024 592128.1 508364.8 675891.4
## May 2024 677756.0 563531.7 791980.3
## Jun 2024 626941.9 488818.4 765065.3
## Jul 2024 546903.3 388445.2 705361.4
## Aug 2024 546792.1 370327.1 723257.0
## Sep 2024 543842.9 351045.7 736640.1
plot(forecast(vendas_mes_ts, 6, 90))
Esta aula é introdutória para o Rmarkdown.Este é o projeto final, que exemplifica uma serie temporal feita atraves de graficos.
summary(vendas_mes)
## ano mes venda_mensal
## Min. :2018 Min. : 1.00 Min. : 83419
## 1st Qu.:2019 1st Qu.: 3.00 1st Qu.:163259
## Median :2021 Median : 6.00 Median :400116
## Mean :2021 Mean : 6.32 Mean :393003
## 3rd Qu.:2022 3rd Qu.: 9.00 3rd Qu.:551466
## Max. :2024 Max. :12.00 Max. :898481
vendas_mes <- Vendas2024 %>% group_by(ano, mes) %>% summarise(venda_mensal = sum(venda_diaria)) %>% arrange(ano, mes)
plot(vendas_mes$venda_mensal)
vendas_mes_ts <- ts(vendas_mes$venda_mensal, start = c(2018,1), frequency = 12) plot(vendas_mes_ts)
decomp_vendas_mes <- decompose(vendas_mes_ts, type = ‘additive’)
plot(decomp_vendas_mes) forecast(vendas_mes_ts, 6, 90)
plot(forecast(vendas_mes_ts, 6, 90))
You can also embed plots, for example:
plot(vendas_mes)
vendas_mes <- Vendas2024 %>%
group_by(ano, mes) %>%
summarise(venda_mensal = sum(venda_diaria)) %>%
arrange(ano, mes)
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
plot(vendas_mes$venda_mensal)
vendas_mes_ts <- ts(vendas_mes$venda_mensal, start = c(2018,1), frequency = 12)
plot(vendas_mes_ts)
decomp_vendas_mes <- decompose(vendas_mes_ts, type = 'additive')
plot(decomp_vendas_mes)
forecast(vendas_mes_ts, 6, 90)
## Point Forecast Lo 90 Hi 90
## Apr 2024 592128.1 508364.8 675891.4
## May 2024 677756.0 563531.7 791980.3
## Jun 2024 626941.9 488818.4 765065.3
## Jul 2024 546903.3 388445.2 705361.4
## Aug 2024 546792.1 370327.1 723257.0
## Sep 2024 543842.9 351045.7 736640.1
plot(forecast(vendas_mes_ts, 6, 90))
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.