#Baixar Biblioteca para suporte
library(zoo)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(colorizer)
library(readxl)
library(tseries)
library(patchwork)
library(mFilter)
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(quantmod)
## Loading required package: 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
## Loading required package: TTR
library(fpp2)
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ ggplot2 3.4.4 ✔ expsmooth 2.3
## ✔ fma 2.5
##
library(DMwR2)
##
## Attaching package: 'DMwR2'
## The following object is masked from 'package:fma':
##
## sales
library(naivebayes)
## naivebayes 0.9.7 loaded
library(neuralnet)
##
## Attaching package: 'neuralnet'
## The following object is masked from 'package:dplyr':
##
## compute
library(stats)
library(stats)
library(plogr)
library(ggplot2)
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(dplyr)
library(readr)
library(forecast)
library(tseries)
library(data.table)
##
## Attaching package: 'data.table'
## The following object is masked from 'package:naivebayes':
##
## tables
## The following objects are masked from 'package:xts':
##
## first, last
## The following objects are masked from 'package:dplyr':
##
## between, first, last
Existe a expectativa de aumento paulatino de força de trabalho nos próximos 12 meses e há necessidade de realizar uma previsão bastante realista vendas e dos gastos com pessoal (pagamento) e encargos trabalhistas. Esse é o segundo desafio: considerando as tendências, sazonalidades e erros do modelo, preveja o gasto com pessoal (pagamentos considerando as vendas e encargos trabalhistas - INSS do empregador - 20% e FGTS, 8%) nos próximos 12 meses.
teste
library(readxl)
Vendas <- read_excel("Vendas.xlsx")
print(Vendas)
## # A tibble: 113,202 × 5
## vendedor dias venda_diaria ano mes
## <dbl> <chr> <dbl> <dbl> <dbl>
## 1 101101 2017-1-1 372. 2017 1
## 2 101101 2017-1-1 139. 2017 1
## 3 101101 2017-1-1 354. 2017 1
## 4 101101 2017-1-1 241. 2017 1
## 5 101101 2017-1-1 123. 2017 1
## 6 101101 2017-1-1 165. 2017 1
## 7 101101 2017-1-1 253. 2017 1
## 8 101101 2017-1-1 393. 2017 1
## 9 101101 2017-1-1 304. 2017 1
## 10 101101 2017-1-1 255. 2017 1
## # ℹ 113,192 more rows
library(readxl)
Salario_base <- read_excel("Salario_base.xlsx")
print(Salario_base)
## # A tibble: 22 × 7
## `Número de Inscrição` Nome Sobrenome Setor Cargo Contrato
## <dbl> <chr> <chr> <chr> <chr> <dttm>
## 1 101101 Nome1 Sobrenome1 Operação Operad… 2017-01-01 00:00:00
## 2 101102 Nome2 Sobrenome2 Operação Operad… 2017-01-02 00:00:00
## 3 101103 Nome3 Sobrenome3 Operação Operad… 2017-08-01 00:00:00
## 4 101104 Nome4 Sobrenome4 Operação Operad… 2018-10-01 00:00:00
## 5 101105 Nome5 Sobrenome5 Operação Operad… 2018-10-01 00:00:00
## 6 101106 Nome6 Sobrenome6 Operação Operad… 2018-10-01 00:00:00
## 7 101107 Nome7 Sobrenome7 Operação Operad… 2019-03-01 00:00:00
## 8 101108 Nome8 Sobrenome8 Operação Operad… 2019-03-01 00:00:00
## 9 101109 Nome9 Sobrenome9 Operação Operad… 2021-05-01 00:00:00
## 10 101110 Nome10 Sobrenome10 Operação Operad… 2021-05-01 00:00:00
## # ℹ 12 more rows
## # ℹ 1 more variable: Salario_base <dbl>
vendas_mes <- Vendas %>%
group_by(ano, mes) %>%
summarise(vendas_mes = sum(venda_diaria)) %>%
arrange(ano, mes)
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
comissoes_mes <- vendas_mes[,3] * 0.05 # 5% SOBRE VENDAS REALIZADAS PARA TODOS
encargos_mes <- vendas_mes[,3] * 0.28 # INSS DO EMPREGADOR 20% + FGTS 8% = 28% DE ENCARGOS
gastos_mes <- encargos_mes + comissoes_mes
#GRÁFICOS - TENDÊNCIA , SAZONALIDADE E ERROS
ts_comissoes_mes1 <- ts(comissoes_mes, start = c(2017,1),
frequency = 12)
plot(ts_comissoes_mes1)
plot(decompose(ts_comissoes_mes1))
forecast(ts_comissoes_mes1,12,50)
## Point Forecast Lo 50 Hi 50
## Apr 2023 29679.13 27980.33 31377.92
## May 2023 33757.28 31420.70 36093.86
## Jun 2023 31327.49 28493.19 34161.80
## Jul 2023 27859.17 24602.33 31116.00
## Aug 2023 27269.83 23639.31 30900.35
## Sep 2023 27147.43 23178.25 31116.61
## Oct 2023 30091.89 25810.76 34373.02
## Nov 2023 33347.66 28775.81 37919.50
## Dec 2023 37603.51 32758.36 42448.66
## Jan 2024 27134.92 22031.09 32238.76
## Feb 2024 24178.12 18828.08 29528.15
## Mar 2024 27631.18 22045.74 33216.62
plot(forecast(ts_comissoes_mes1,12,50))
autoplot(ts_comissoes_mes1)
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.