Para Arca Continental su principal canal de distribución es el canal tradicional, es decir, las tienditas de la esquina. Esto permite que la familia de productos de la compañía Coca Cola estén siempre cerca de sus consumidores a través de estas pequeñas empresas familiares que forman parte de su propia comunidad. Esto, por los altos márgenes de ganancias y políticas restrictivas que imponen las grandes cadenas de supermercados y las tiendas de conveniencia para aceptar poner a la venta en sus establecimientos los productos de cualquier empresa. Así pues, como deben ser todos los negocios, socialmente responsables, en el Proyecto Siglo XXI de Arca hay un “ganar ganar” tanto para los tenderos como para la empresa Arca Continental.
# install.packages("readxl") # Leer documentos de excel
library(readxl)
# install.packages("tidyverse") # Manipulación de datos
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# install.packages("ggplot2") # Generar gráficos presentables
library(ggplot2)
# install.packages("forecast") # Generar series de tiempo y pronósticos
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
# install.packages("DataExplorer") # Para realizar Análisis Descriptivo
library(DataExplorer)
# install.packages("dplyr")
library(dplyr)
# file.choose()
df <- read_excel("/Users/adrianelizondo/Downloads/Datos Arca Continental Original.xlsx")
colnames(df) <- make.names(colnames(df))
summary(df)
## ID Año Territorio Sub.Territorio
## Min. : 1 Min. :2016 Length:466509 Length:466509
## 1st Qu.:116628 1st Qu.:2017 Class :character Class :character
## Median :233255 Median :2018 Mode :character Mode :character
## Mean :233255 Mean :2018
## 3rd Qu.:349882 3rd Qu.:2019
## Max. :466509 Max. :2019
##
## CEDI Cliente Nombre Tamaño.Cte.Industria
## Length:466509 Length:466509 Length:466509 Length:466509
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Segmento.Det Marca Presentacion Tamaño
## Length:466509 Length:466509 Length:466509 Length:466509
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Retornable_NR Enero Febrero Marzo
## Length:466509 Min. : -19.0 Min. : -11.00 Min. : -32.00
## Class :character 1st Qu.: 1.0 1st Qu.: 1.00 1st Qu.: 1.00
## Mode :character Median : 2.0 Median : 2.00 Median : 3.00
## Mean : 10.1 Mean : 9.76 Mean : 11.36
## 3rd Qu.: 6.0 3rd Qu.: 6.00 3rd Qu.: 6.00
## Max. :42736.0 Max. :42767.00 Max. :42795.00
## NA's :233480 NA's :231213 NA's :227420
## Abril Mayo Junio Julio
## Min. : -70.00 Min. : -106.00 Min. : -211.0 Min. : -60.00
## 1st Qu.: 1.00 1st Qu.: 1.00 1st Qu.: 1.0 1st Qu.: 1.00
## Median : 3.00 Median : 3.00 Median : 3.0 Median : 2.00
## Mean : 11.71 Mean : 12.75 Mean : 12.2 Mean : 11.75
## 3rd Qu.: 6.00 3rd Qu.: 7.00 3rd Qu.: 6.0 3rd Qu.: 6.00
## Max. :42826.00 Max. :42856.00 Max. :42887.0 Max. :42917.00
## NA's :224057 NA's :216910 NA's :215753 NA's :223411
## Agosto Septiembre Octubre Noviembre
## Min. : -211.00 Min. : -527.0 Min. : -38.0 Min. : -25.0
## 1st Qu.: 1.00 1st Qu.: 1.0 1st Qu.: 1.0 1st Qu.: 1.0
## Median : 3.00 Median : 3.0 Median : 3.0 Median : 3.0
## Mean : 11.98 Mean : 13.4 Mean : 13.7 Mean : 13.3
## 3rd Qu.: 6.00 3rd Qu.: 7.0 3rd Qu.: 7.0 3rd Qu.: 6.0
## Max. :42948.00 Max. :42979.0 Max. :43009.0 Max. :43040.0
## NA's :220242 NA's :337314 NA's :338386 NA's :338460
## Diciembre
## Min. : -28.0
## 1st Qu.: 1.0
## Median : 3.0
## Mean : 14.8
## 3rd Qu.: 7.0
## Max. :43070.0
## NA's :341855
str(df)
## tibble [466,509 × 25] (S3: tbl_df/tbl/data.frame)
## $ ID : num [1:466509] 1 2 3 4 5 6 7 8 9 10 ...
## $ Año : num [1:466509] 2016 2016 2016 2016 2016 ...
## $ Territorio : chr [1:466509] "Guadalajara" "Guadalajara" "Guadalajara" "Guadalajara" ...
## $ Sub.Territorio : chr [1:466509] "Belenes" "Belenes" "Belenes" "Belenes" ...
## $ CEDI : chr [1:466509] "Suc. Belenes" "Suc. Belenes" "Suc. Belenes" "Suc. Belenes" ...
## $ Cliente : chr [1:466509] "77737" "77737" "77737" "77737" ...
## $ Nombre : chr [1:466509] "ABARR" "ABARR" "ABARR" "ABARR" ...
## $ Tamaño.Cte.Industria: chr [1:466509] "Extra Grande" "Extra Grande" "Extra Grande" "Extra Grande" ...
## $ Segmento.Det : chr [1:466509] "Agua Mineral" "Agua Purificada" "Agua Purificada" "Agua Saborizada" ...
## $ Marca : chr [1:466509] "Topo Chico A.M." "Ciel Agua Purificada" "Ciel Agua Purificada" "Ciel Exprim" ...
## $ Presentacion : chr [1:466509] "600 ml NR" "1 Ltro. N.R." "1.5 Lts. NR" "600 ml NR" ...
## $ Tamaño : chr [1:466509] "Individual" "Individual" "Individual" "Individual" ...
## $ Retornable_NR : chr [1:466509] "No Retornable" "No Retornable" "No Retornable" "No Retornable" ...
## $ Enero : num [1:466509] NA NA NA NA NA NA 1 NA 3 NA ...
## $ Febrero : num [1:466509] NA 2 NA NA NA NA NA 1 3 NA ...
## $ Marzo : num [1:466509] NA 8 3 NA NA 1 NA NA 4 NA ...
## $ Abril : num [1:466509] NA 4 6 NA NA NA NA 1 4 NA ...
## $ Mayo : num [1:466509] NA 4 3 NA NA NA 0 NA 4 NA ...
## $ Junio : num [1:466509] NA 2 3 NA NA NA NA 1 4 0 ...
## $ Julio : num [1:466509] NA 2 3 NA NA NA 0 NA 4 NA ...
## $ Agosto : num [1:466509] NA 2 3 NA NA NA NA 1 7 NA ...
## $ Septiembre : num [1:466509] NA 2 3 NA NA NA NA 1 4 NA ...
## $ Octubre : num [1:466509] NA 2 3 NA NA NA 0 NA 3 NA ...
## $ Noviembre : num [1:466509] NA 4 3 NA 0 NA NA NA 1 NA ...
## $ Diciembre : num [1:466509] 1 2 3 1 NA NA NA NA 3 NA ...
# create_report(df)
introduce(df)
## # A tibble: 1 × 9
## rows columns discrete_columns continuous_columns all_missing_columns
## <int> <int> <int> <int> <int>
## 1 466509 25 11 14 0
## # ℹ 4 more variables: total_missing_values <int>, complete_rows <int>,
## # total_observations <int>, memory_usage <dbl>
plot_intro(df)
plot_missing(df)
plot_histogram(df)
plot_bar(df)
plot_correlation(df)
count(df, Territorio, sort=TRUE)
## # A tibble: 2 × 2
## Territorio n
## <chr> <int>
## 1 Guadalajara 466508
## 2 Territorio 1
count(df, Sub.Territorio, sort=TRUE)
## # A tibble: 4 × 2
## Sub.Territorio n
## <chr> <int>
## 1 Belenes 208982
## 2 Huentitán 144196
## 3 Toluquilla 113330
## 4 Sub Territorio 1
count(df, CEDI, sort=TRUE)
## # A tibble: 4 × 2
## CEDI n
## <chr> <int>
## 1 Suc. Belenes 208982
## 2 Suc. Huentitán 144196
## 3 Suc. Toluquilla 113330
## 4 CEDI 1
count(df, Cliente, sort=TRUE)
## # A tibble: 5,249 × 2
## Cliente n
## <chr> <int>
## 1 0286 647
## 2 2912 586
## 3 2661 537
## 4 7821 531
## 5 1859 525
## 6 5583 516
## 7 9998 508
## 8 3601 506
## 9 5879 499
## 10 0335 496
## # ℹ 5,239 more rows
count(df, Nombre, sort=TRUE)
## # A tibble: 1,090 × 2
## Nombre n
## <chr> <int>
## 1 ABARR 71186
## 2 MARIA 39816
## 3 JOSE 17479
## 4 JUAN 7580
## 5 MARTH 5759
## 6 MISCE 5700
## 7 LUIS 5585
## 8 SUPER 4565
## 9 CARLO 3991
## 10 ROSA 3890
## # ℹ 1,080 more rows
count(df, Tamaño.Cte.Industria, sort=TRUE)
## # A tibble: 5 × 2
## Tamaño.Cte.Industria n
## <chr> <int>
## 1 Extra Grande 230190
## 2 Micro 117110
## 3 Pequeño 77875
## 4 Grande 41333
## 5 Tamaño Cte Industria 1
count(df, Segmento.Det, sort=TRUE)
## # A tibble: 21 × 2
## Segmento.Det n
## <chr> <int>
## 1 Sabores Regular 156242
## 2 Colas Regular 95720
## 3 Colas Light 43807
## 4 Jugos y Néctares 33362
## 5 Bebidas de Fruta 30641
## 6 Agua Purificada 20766
## 7 Agua Mineral 12590
## 8 Isotónicos Regular 11905
## 9 Té Regular 10062
## 10 Agua Saborizada 10056
## # ℹ 11 more rows
count(df, Marca, sort=TRUE)
## # A tibble: 56 × 2
## Marca n
## <chr> <int>
## 1 Coca-Cola 95720
## 2 Sprite 37925
## 3 Fanta 35728
## 4 Fresca 26435
## 5 Manzana Lift 25598
## 6 Coca-Cola Light 21926
## 7 Del Valle 21325
## 8 Ciel Agua Purificada 20766
## 9 Sidral Mundet 17150
## 10 Valle Frut 15808
## # ℹ 46 more rows
count(df, Presentacion, sort=TRUE)
## # A tibble: 57 × 2
## Presentacion n
## <chr> <int>
## 1 600 ml NR 74008
## 2 1 Ltro. N.R. 36930
## 3 2 Lts. NR 36415
## 4 500 ml Ret 35165
## 5 1.5 Lts. NR 30637
## 6 Lata 235 ml 24551
## 7 400 ml NR 22877
## 8 250 ml. NR PET 21735
## 9 500 ml NR Vidrio 18758
## 10 2.5 Lts. NR 13235
## # ℹ 47 more rows
count(df, Tamaño, sort=TRUE)
## # A tibble: 3 × 2
## Tamaño n
## <chr> <int>
## 1 Individual 328513
## 2 Familiar 137995
## 3 Tamaño 1
count(df, Retornable_NR, sort=TRUE)
## # A tibble: 3 × 2
## Retornable_NR n
## <chr> <int>
## 1 No Retornable 403226
## 2 Retornable 63282
## 3 Retornable_NR 1
## Revisar NAs en la base de datos
# ¿Cuántos NAs tengo en la base de datos?
sum(is.na(df))
## [1] 3148501
# ¿Cuántos NAs tengo por variable?
sapply(df, function(x) sum(is.na(x)))
## ID Año Territorio
## 0 0 0
## Sub.Territorio CEDI Cliente
## 0 0 0
## Nombre Tamaño.Cte.Industria Segmento.Det
## 0 0 0
## Marca Presentacion Tamaño
## 0 0 0
## Retornable_NR Enero Febrero
## 0 233480 231213
## Marzo Abril Mayo
## 227420 224057 216910
## Junio Julio Agosto
## 215753 223411 220242
## Septiembre Octubre Noviembre
## 337314 338386 338460
## Diciembre
## 341855
# Opción 1. Eliminar NAs
# df1 <- na.omit(df)
# Opción 2. Reemplazar NAs con CEROS
df[is.na(df)] <- 0
sum(is.na(df))
## [1] 0
# Opción 3. Reemplazar NAs con PROMEDIO
# df1 <- df
# df1$Enero[is.na(df1$Enero)] <- mean(df1$Enero, na.rm=TRUE)
boxplot(df$Enero)
# Eliminar renglón de los totales
df <- df[df$Enero <6000, ]
boxplot(df$Enero)
#Crear una nueva base de datos
df1 <- df
# Muestra las ventas de Enero a Junio por CEDI:
df2 <- select(df1,c(CEDI,Enero:Junio))
# Muestra los movimientos por Cedi y tamaño de tienda grande:
df3 <- df1 %>% filter(Tamaño.Cte.Industria == "Grande")
# Ordena la base de datos por Cedi, por marca y por presentación:
df4 <- df1 %>% arrange(CEDI, Marca, Presentacion)
# Agrega un campo calculado con las ventas del primer semestre y muestra las ventas del primer semestre por marca:
df5 <- df1 %>%
mutate(Ventas_Sem1 = Enero + Febrero + Marzo + Abril + Mayo + Junio)
ventas_sem1_por_marca <- df5 %>%
group_by(Marca) %>%
summarise(Ventas_Sem1=sum(Ventas_Sem1))
# Obtén la media de las ventas del primer semestre agrupado por marca, presentación y tamaño.
df6 <- df5 %>%
group_by(Marca, Presentacion, Tamaño) %>%
summarise(Ventas_Sem1=mean(Ventas_Sem1))
## `summarise()` has grouped output by 'Marca', 'Presentacion'. You can override
## using the `.groups` argument.
summary(df1)
## ID Año Territorio Sub.Territorio
## Min. : 1 Min. :2016 Length:466508 Length:466508
## 1st Qu.:116628 1st Qu.:2017 Class :character Class :character
## Median :233256 Median :2018 Mode :character Mode :character
## Mean :233255 Mean :2018
## 3rd Qu.:349882 3rd Qu.:2019
## Max. :466509 Max. :2019
## CEDI Cliente Nombre Tamaño.Cte.Industria
## Length:466508 Length:466508 Length:466508 Length:466508
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Segmento.Det Marca Presentacion Tamaño
## Length:466508 Length:466508 Length:466508 Length:466508
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Retornable_NR Enero Febrero Marzo
## Length:466508 Min. : -19.000 Min. : -11.000 Min. : -32.000
## Class :character 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000
## Mode :character Median : 0.000 Median : 0.000 Median : 0.000
## Mean : 4.951 Mean : 4.829 Mean : 5.729
## 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 3.000
## Max. :5333.000 Max. :4995.000 Max. :5636.000
## Abril Mayo Junio Julio
## Min. : -70.000 Min. :-106.00 Min. :-211.000 Min. : -60.000
## 1st Qu.: 0.000 1st Qu.: 0.00 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 0.000 Median : 0.00 Median : 0.000 Median : 0.000
## Mean : 5.992 Mean : 6.73 Mean : 6.464 Mean : 6.033
## 3rd Qu.: 3.000 3rd Qu.: 3.00 3rd Qu.: 3.000 3rd Qu.: 3.000
## Max. :6164.000 Max. :6759.00 Max. :6033.000 Max. :6735.000
## Agosto Septiembre Octubre Noviembre
## Min. :-211.000 Min. :-527.000 Min. : -38.000 Min. : -25.00
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.00
## Median : 0.000 Median : 0.000 Median : 0.000 Median : 0.00
## Mean : 6.235 Mean : 3.625 Mean : 3.674 Mean : 3.57
## 3rd Qu.: 3.000 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.00
## Max. :6065.000 Max. :6509.000 Max. :6326.000 Max. :5319.00
## Diciembre
## Min. : -28.000
## 1st Qu.: 0.000
## Median : 0.000
## Mean : 3.858
## 3rd Qu.: 0.000
## Max. :6182.000
df7 <- gather(df1, Mes, Ventas, Enero:Diciembre)
df7
## # A tibble: 5,598,096 × 15
## ID Año Territorio Sub.Territorio CEDI Cliente Nombre
## <dbl> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 1 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 2 2 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 3 3 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 4 4 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 5 5 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 6 6 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 7 7 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 8 8 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 9 9 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## 10 10 2016 Guadalajara Belenes Suc. Belenes 77737 ABARR
## # ℹ 5,598,086 more rows
## # ℹ 8 more variables: Tamaño.Cte.Industria <chr>, Segmento.Det <chr>,
## # Marca <chr>, Presentacion <chr>, Tamaño <chr>, Retornable_NR <chr>,
## # Mes <chr>, Ventas <dbl>
# Agregar una columna con el Número de Mes
meses <- c("Enero"="01", "Febrero"="02","Marzo"="03", "Abril"="04", "Mayo"="05", "Junio"="06", "Julio"="07", "Agosto"="08", "Septiembre"="09", "Octubre"="10", "Noviembre"="11", "Diciembre"="12")
df7$Número_de_Mes <- meses[df7$Mes]
# Graficar el total de ventas por mes y año
ventas.totales <- df7 %>%
group_by(Año, Número_de_Mes) %>%
summarise(Ventas.Totales = sum(Ventas)) %>%
arrange(Número_de_Mes)
## `summarise()` has grouped output by 'Año'. You can override using the `.groups`
## argument.
ggplot(ventas.totales, aes(x=Número_de_Mes, y=Ventas.Totales,group=Año, color= as.factor(Año))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", color = "Año")
# Elaborar Regresión Lineal
ventas_4567 <- df7 %>%
filter(Cliente == "4567") %>%
group_by(Año) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
filter(Ventas_Totales != 0)
# ventas_4567$Secuencia <- 1:nrow(ventas_4567)
ggplot(ventas_4567, aes(x=Año, y=Ventas_Totales)) +
geom_point() +
labs(x="Año",y="Ventas Totales(Qty)", title= "Ventas Totales del Cliente 4567")
regresion <- lm(Ventas_Totales ~ Año, data=ventas_4567)
summary(regresion)
##
## Call:
## lm(formula = Ventas_Totales ~ Año, data = ventas_4567)
##
## Residuals:
## 1 2 3
## -5092 10185 -5092
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 48918677 17799125 2.748 0.222
## Año -24174 8820 -2.741 0.223
##
## Residual standard error: 12470 on 1 degrees of freedom
## Multiple R-squared: 0.8825, Adjusted R-squared: 0.765
## F-statistic: 7.512 on 1 and 1 DF, p-value: 0.2227
# Ecuación
# y = 48918677 - 24174 * Año
# R cuadrada ajustada
# 77%
datos <- data.frame(Año=2020:2025)
prediccion <- predict(regresion,datos)
prediccion
## 1 2 3 4 5 6
## 87197.333 63023.333 38849.333 14675.333 -9498.667 -33672.667
ventas_4567$Tipo_de_Dato <- "Datos Reales"
datos$Ventas_Totales <- prediccion
datos$Tipo_de_Dato <- "Predicción"
datos_combinados <- rbind(ventas_4567,datos)
ggplot(datos_combinados, aes(x=Año, y=Ventas_Totales, color=Tipo_de_Dato)) +
geom_point() +
labs(x="Año",y="Ventas Totales(Qty)", title= "Pronóstico a 5 años de Ventas del Cliente 4567")
ventas_mensuales_4567 <- df7 %>%
filter(Cliente == "4567") %>%
group_by(Año, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
filter(Ventas_Totales != 0)
## `summarise()` has grouped output by 'Año'. You can override using the `.groups`
## argument.
# Confirmar que los datos que queremos modelar esten ordenados cronológicamente.
# Función de Serie de Tiempo MENSUAL, que inicia en Enero 2017
ts <- ts(data=ventas_mensuales_4567$Ventas_Totales, start = c(2017,1), frequency = 12)
# Función de Serie de Tiempo MENSUAL, que inicia en Abril 2017
# ts <- ts(data=ventas_mensuales_4567$Ventas_Totales, start = c(2017,4), frequency = 12)
# Función de Serie de Tiempo TRIMESTRAL, que inicia en Enero 2017
# ts <- ts(data=ventas_mensuales_4567$Ventas_Totales, start = c(2017,1), frequency = 4)
# Función de Serie de Tiempo TRIMESTRAL, que inicia en Octubre 2017 (Q4)
# ts <- ts(data=ventas_mensuales_4567$Ventas_Totales, start = c(2017,4), frequency = 4)
# Función de Serie de Tiempo ANUAL, que inicia en 2017
# ts <- ts(data=ventas_mensuales_4567$Ventas_Totales, start = 2017, frequency = 1)
# Crear Modelo ARIMA
# Modelo Autorregresivo Integrado de Promedio Movil.
arima <- auto.arima(ts, D=1) # D=1 por la temporalidad
arima
## Series: ts
## ARIMA(0,0,0)(0,1,0)[12]
##
## sigma^2 = 10383172: log likelihood = -189.94
## AIC=381.87 AICc=382.09 BIC=382.87
summary(arima)
## Series: ts
## ARIMA(0,0,0)(0,1,0)[12]
##
## sigma^2 = 10383172: log likelihood = -189.94
## AIC=381.87 AICc=382.09 BIC=382.87
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -36.98041 2547.446 1572.02 -1.811657 13.08459 0.6269271 0.2519497
# Generar el pronóstico de ventas
pronostico <- forecast(arima, level=95, h=36)
pronostico
## Point Forecast Lo 95 Hi 95
## Sep 2019 12086 5770.4219 18401.58
## Oct 2019 11427 5111.4219 17742.58
## Nov 2019 11270 4954.4219 17585.58
## Dec 2019 12227 5911.4219 18542.58
## Jan 2020 9430 3114.4219 15745.58
## Feb 2020 11312 4996.4219 17627.58
## Mar 2020 12515 6199.4219 18830.58
## Apr 2020 13334 7018.4219 19649.58
## May 2020 16286 9970.4219 22601.58
## Jun 2020 15347 9031.4219 21662.58
## Jul 2020 14005 7689.4219 20320.58
## Aug 2020 14050 7734.4219 20365.58
## Sep 2020 12086 3154.4238 21017.58
## Oct 2020 11427 2495.4238 20358.58
## Nov 2020 11270 2338.4238 20201.58
## Dec 2020 12227 3295.4238 21158.58
## Jan 2021 9430 498.4238 18361.58
## Feb 2021 11312 2380.4238 20243.58
## Mar 2021 12515 3583.4238 21446.58
## Apr 2021 13334 4402.4238 22265.58
## May 2021 16286 7354.4238 25217.58
## Jun 2021 15347 6415.4238 24278.58
## Jul 2021 14005 5073.4238 22936.58
## Aug 2021 14050 5118.4238 22981.58
## Sep 2021 12086 1147.0979 23024.90
## Oct 2021 11427 488.0979 22365.90
## Nov 2021 11270 331.0979 22208.90
## Dec 2021 12227 1288.0979 23165.90
## Jan 2022 9430 -1508.9021 20368.90
## Feb 2022 11312 373.0979 22250.90
## Mar 2022 12515 1576.0979 23453.90
## Apr 2022 13334 2395.0979 24272.90
## May 2022 16286 5347.0979 27224.90
## Jun 2022 15347 4408.0979 26285.90
## Jul 2022 14005 3066.0979 24943.90
## Aug 2022 14050 3111.0979 24988.90
plot(pronostico, main="Ventas Mensuales y Pronóstico a 3 Años del Cliente 4567", xlab="Año", ylab="Ventas (Qty)")
ventas_totales_seg <- df7 %>%
filter(Segmento.Det == "Agua Purificada" | Segmento.Det == "Isotónicos Regular" | Segmento.Det == "Colas Regular" ) %>%
filter(Año == 2018) %>%
group_by(Segmento.Det, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
arrange(Número_de_Mes)
## `summarise()` has grouped output by 'Segmento.Det'. You can override using the
## `.groups` argument.
ggplot(ventas_totales_seg, aes(x=Número_de_Mes, y=Ventas_Totales,group=Segmento.Det, color= as.factor(Segmento.Det))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", title= "Ventas Totales por Segmento", color = "Segmento")
ventas_totales_tam_cliente <- df7 %>%
filter(Año == 2019) %>%
group_by(Tamaño.Cte.Industria, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
arrange(Número_de_Mes) %>%
filter(Ventas_Totales != 0)
## `summarise()` has grouped output by 'Tamaño.Cte.Industria'. You can override
## using the `.groups` argument.
ggplot(ventas_totales_tam_cliente, aes(x=Número_de_Mes, y=Ventas_Totales,group=Tamaño.Cte.Industria, color= as.factor(Tamaño.Cte.Industria))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", title= "Ventas Totales por Tamaño de Cliente", color = "Tamaño de Cliente")
ventas_totales_marca <- df7 %>%
filter(Año == 2019) %>%
filter(Marca == c("Coca-Cola", "Valle Frut", "Ciel Agua Purificada","Coca-Cola Light")) %>%
group_by(Marca, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
arrange(Número_de_Mes) %>%
filter(Ventas_Totales != 0)
## `summarise()` has grouped output by 'Marca'. You can override using the
## `.groups` argument.
ggplot(ventas_totales_marca, aes(x=Número_de_Mes, y=Ventas_Totales,group=Marca, color= as.factor(Marca))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", title= "Ventas Totales por Marca", color = "Marca")
ventas_totales_envase <- df7 %>%
filter(Retornable_NR=="Retornable") %>%
filter(Año == c(2017,2018,2019)) %>%
group_by(Año, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
arrange(Número_de_Mes) %>%
filter(Ventas_Totales != 0)
## `summarise()` has grouped output by 'Año'. You can override using the `.groups`
## argument.
ggplot(ventas_totales_envase, aes(x=Número_de_Mes, y=Ventas_Totales,group=Año, color= as.factor(Año))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", title= "Ventas Totales de Envases Retornables", color = "Año")
ventas_totales_seg <- df7 %>%
filter(Segmento.Det == "Agua Purificada" | Segmento.Det == "Isotónicos Regular" | Segmento.Det == "Colas Regular" ) %>%
filter(Año == 2018) %>%
group_by(Segmento.Det, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
arrange(Número_de_Mes)
## `summarise()` has grouped output by 'Segmento.Det'. You can override using the
## `.groups` argument.
ggplot(ventas_totales_seg, aes(x=Número_de_Mes, y=Ventas_Totales,group=Segmento.Det, color= as.factor(Segmento.Det))) +
geom_line() +
geom_point() +
labs(x="Mes",y="Ventas Totales(Qty)", title= "Ventas Totales por Segmento", color = "Segmento")
ventas_totales_ayr <- df7 %>%
filter(Segmento.Det == c("Agua Purificada", "Colas Regular")) %>%
group_by(Segmento.Det, Año) %>%
summarise(Ventas_Totales = sum(Ventas))
## `summarise()` has grouped output by 'Segmento.Det'. You can override using the
## `.groups` argument.
ggplot(ventas_totales_ayr, aes(x=Año, y=Ventas_Totales,group=Segmento.Det, color= as.factor(Segmento.Det))) +
geom_line() +
geom_point() +
labs(x="Año",y="Ventas Totales(Qty)", title= "Ventas Totales por Segmento", color = "Segmento")
ventas_coca_vidrio <- df7 %>%
filter(Marca == "Coca-Cola" & Presentacion == "500 ml NR Vidrio") %>%
group_by(Año, Número_de_Mes) %>%
summarise(Ventas_Totales = sum(Ventas)) %>%
filter(Ventas_Totales != 0)
## `summarise()` has grouped output by 'Año'. You can override using the `.groups`
## argument.
# Confirmar que los datos que queremos modelar esten ordenados cronológicamente.
# Función de Serie de Tiempo MENSUAL, que inicia en Enero 2017
ts <- ts(data=ventas_coca_vidrio$Ventas_Totales, start = c(2016,1), frequency = 12)
# Crear Modelo ARIMA
# Modelo Autorregresivo Integrado de Promedio Movil.
arima <- auto.arima(ts, D=1) # D=1 por la temporalidad
arima
## Series: ts
## ARIMA(1,0,0)(0,1,0)[12] with drift
##
## Coefficients:
## ar1 drift
## 0.7092 719.7436
## s.e. 0.1328 299.8430
##
## sigma^2 = 41602809: log likelihood = -325.42
## AIC=656.84 AICc=657.7 BIC=661.24
summary(arima)
## Series: ts
## ARIMA(1,0,0)(0,1,0)[12] with drift
##
## Coefficients:
## ar1 drift
## 0.7092 719.7436
## s.e. 0.1328 299.8430
##
## sigma^2 = 41602809: log likelihood = -325.42
## AIC=656.84 AICc=657.7 BIC=661.24
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 48.66702 5325.932 3245.859 -1.373606 8.085645 0.3668337 -0.1551565
# Generar el pronóstico de ventas
pronostico <- forecast(arima, level=95, h=16)
pronostico
## Point Forecast Lo 95 Hi 95
## Sep 2019 57009.58 44367.77 69651.40
## Oct 2019 47611.62 32113.16 63110.08
## Nov 2019 43891.25 27139.04 60643.45
## Dec 2019 49988.01 32639.38 67336.63
## Jan 2020 52649.69 35008.69 70290.69
## Feb 2020 59116.66 41330.41 76902.91
## Mar 2020 63214.67 45355.81 81073.53
## Apr 2020 45929.93 28034.66 63825.21
## May 2020 77894.00 59980.44 95807.57
## Jun 2020 66917.27 48994.51 84840.02
## Jul 2020 65104.33 47176.96 83031.71
## Aug 2020 66475.77 48546.08 84405.47
## Sep 2020 65846.40 43789.47 87903.33
## Oct 2020 56390.31 32525.70 80254.93
## Nov 2020 52628.72 27904.75 77352.68
## Dec 2020 58696.24 33551.13 83841.36
plot(pronostico, main="Ventas Mensuales y Pronóstico para 2020 de Coca-Cola 500 ml NR Vidrio", xlab="Año", ylab="Ventas (Qty)")