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.
Sin embargo, este tipo de formato de Retail está enfrentando una fuerte competencia por parte de los canales modernos. En un principio fueron las tiendas de conveniencia como Oxxo y 7-Eleven quienes comenzaron a crear una importante cantidad de nuevos establecimientos, cada vez más en zonas habitacionales y no solo en avenidas o gasolineras.
#install.packages("readxl") #Para importar un archivo de Excel
library(readxl)
#install.packages("DataExplorer") #Para realizar Análisis descriptivo
library(DataExplorer)
#install.packages("dplyr")
library(dplyr)
#install.packages("tidyverse") #Paquete global para manipulación y análisis de datos
library(tidyverse)
#install.packages("forecast") #Para revisar tendencias y generar pronósticos
library(forecast)
#install.packages("ggplot2") #Para generar gráficas con mejor diseño
library(ggplot2)
#file.choose()
df <- read_excel("C:\\Users\\serva\\Downloads\\Datos Arca Continental Original.xlsx")
## Warning: Expecting numeric in N184066 / R184066C14: got a date
## Warning: Expecting numeric in O184066 / R184066C15: got a date
## Warning: Expecting numeric in P184066 / R184066C16: got a date
## Warning: Expecting numeric in Q184066 / R184066C17: got a date
## Warning: Expecting numeric in R184066 / R184066C18: got a date
## Warning: Expecting numeric in S184066 / R184066C19: got a date
## Warning: Expecting numeric in T184066 / R184066C20: got a date
## Warning: Expecting numeric in U184066 / R184066C21: got a date
## Warning: Expecting numeric in V184066 / R184066C22: got a date
## Warning: Expecting numeric in W184066 / R184066C23: got a date
## Warning: Expecting numeric in X184066 / R184066C24: got a date
## Warning: Expecting numeric in Y184066 / R184066C25: got a date
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)
##
##
## processing file: report.rmd
## | | | 0% | |. | 2% | |.. | 5% [global_options] | |... | 7% | |.... | 10% [introduce] | |.... | 12% | |..... | 14% [plot_intro] | |...... | 17% | |....... | 19% [data_structure] | |........ | 21% | |......... | 24% [missing_profile] | |.......... | 26% | |........... | 29% [univariate_distribution_header] | |........... | 31% | |............ | 33% [plot_histogram] | |............. | 36% | |.............. | 38% [plot_density] | |............... | 40% | |................ | 43% [plot_frequency_bar] | |................. | 45% | |.................. | 48% [plot_response_bar] | |.................. | 50% | |................... | 52% [plot_with_bar] | |.................... | 55% | |..................... | 57% [plot_normal_qq] | |...................... | 60% | |....................... | 62% [plot_response_qq] | |........................ | 64% | |......................... | 67% [plot_by_qq] | |.......................... | 69% | |.......................... | 71% [correlation_analysis] | |........................... | 74% | |............................ | 76% [principal_component_analysis] | |............................. | 79% | |.............................. | 81% [bivariate_distribution_header] | |............................... | 83% | |................................ | 86% [plot_response_boxplot] | |................................. | 88% | |................................. | 90% [plot_by_boxplot] | |.................................. | 93% | |................................... | 95% [plot_response_scatterplot] | |.................................... | 98% | |.....................................| 100% [plot_by_scatterplot]
## output file: C:/Users/serva/Downloads/report.knit.md
## "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS "C:\Users\serva\Downloads\report.knit.md" --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc582861e7226c.html --lua-filter "C:\Users\serva\AppData\Local\R\win-library\4.4\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\serva\AppData\Local\R\win-library\4.4\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 6 --template "C:\Users\serva\AppData\Local\R\win-library\4.4\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable theme=yeti --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\serva\AppData\Local\Temp\RtmpwbXS3o\rmarkdown-str5828642136a4.html"
##
## Output created: report.html
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)
## 4 columns ignored with more than 50 categories.
## Cliente: 5249 categories
## Nombre: 1090 categories
## Marca: 56 categories
## Presentacion: 57 categories
plot_correlation(df)
## 5 features with more than 20 categories ignored!
## Cliente: 5249 categories
## Nombre: 1090 categories
## Segmento.Det: 21 categories
## Marca: 56 categories
## Presentacion: 57 categories
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
## 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
#Reemplazar NAs con CEROS
df[is.na(df)] <- 0
sum(is.na(df))
## [1] 0
## Detectar valores atípicos
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.
# Calcular medidas de tendencia central
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
# Colapsar meses en una columna
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)
# 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")
Respuesta: En general las ventas aumentaron en 2019, pero cada
segmento se comportó diferente. El incremento de ventas se puede lograr
gracias a mejores campañas de mercadotecnia y lanzamiento de nuevos
productos.En 2018 la venta de Coca-Cola entre Febrero y Diciembre
aumentó en 100,000 unidades, mientras que las aguas isotónicas no
tuvieron cambios.
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")
Respuesta: El incremento de ventas es similar independientemente de los tamaños de los clientes. Como todos los negocios están abiertos los mismos días, y están ubicados en la misma ciudad (Guadalajara), los factores externos de las ventas efectan casi igual a todos. El mes de mayo de 2019 fue el de mayor ventas en todos los tamaños de cliente, y el primer bimestre fue el más bajo también para todos los tamaños 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")
Respuesta: El comportamiento de ventas es similar entre las marcas a través de los meses, pero hay marcas que venden mucho más que otras. Los meses de más ventas de bebidas son los meses en que la temperatura es mayor, y las marcas más conocidas son las que tiene en mente el consumidor. El mes de mayo 2019 es para todas las marcas el de mayores ventas, pero la marca Coca-Cola es la que vende más que todas.
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")
Respuesta: La venta de productos en envase retornable aumentó en los últimos dos años. Las campañas de conciencia ambiental han vuelto populares las opciones menos dañinas al ecosistema. De 2017 a 2018 hubo un ligero incremento en las ventas de envase retornable, y entre 2018 y 2019 el aumento fue muy notorio.
Notas: Hay otros factores a considerar como que en 2019 hay más tiendas con el proyecto Siglo XXI, o que las tiendas en general venden más productos (tanto retornables como no retornables).
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")
Respuesta: Las ventas de Agua Purificada no ha aumentado en relación a Refrescos o Bebidas Isotónicas. La persepción que el agua no tiene valor agregado en la preparación y el azúcar en la receta hacen de los refrescos la opción preferida de los consumidores mexicanos. En 2018 las ventas totales de Agua Purificada no superaron las 50,000 unidades, mientras que la Coca-Cola vendió en su mes más alto 450,000 (8 veces más que el agua).
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")
Respuesta: La venta de agua y refrescos se incrementa en los mismos meses, y a través de los años, pero no se puede concluir que un incremento cause el otro. Los meses calurosos y el crecimiento de la población hace que las ventas se incrementen en las bebidas, sean agua o refresco. En la gráfica obtenida se observa un incremento año con año en la venta de agua y también de refrescos.
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.6837
## s.e. 0.1328 299.8533
##
## sigma^2 = 41602728: 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.6837
## s.e. 0.1328 299.8533
##
## sigma^2 = 41602728: 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.85447 5325.927 3245.824 -1.37305 8.085494 0.3668297 -0.1551829
# Generar el pronóstico de ventas
pronostico <- forecast(arima, level=95, h=16)
pronostico
## Point Forecast Lo 95 Hi 95
## Sep 2019 57009.75 44367.95 69651.56
## Oct 2019 47611.80 32113.20 63110.40
## Nov 2019 43891.36 27138.87 60643.85
## Dec 2019 49988.01 32639.01 67337.02
## Jan 2020 52649.58 35008.14 70291.03
## Feb 2020 59116.44 41329.71 76903.18
## Mar 2020 63214.35 45354.98 81073.72
## Apr 2020 45929.53 28033.74 63825.33
## May 2020 77893.53 59979.44 95807.63
## Jun 2020 66916.74 48993.45 84840.03
## Jul 2020 65103.76 47175.85 83031.68
## Aug 2020 66475.17 48544.93 84405.41
## Sep 2020 65845.94 43788.54 87903.34
## Oct 2020 56389.84 32524.67 80255.02
## Nov 2020 52628.16 27903.54 77352.78
## Dec 2020 58695.56 33549.72 83841.40
plot(pronostico, main="Ventas Mensuales y Pronóstico para 2020 de Coca-Cola 500 ml NR Vidrio", xlab="Año", ylab="Ventas (Qty)")
Respuesta: Las ventas esperadas de Coca-Cola de 500 ml NR Vidrio para 2020 oscilan mensualmente entre 45,000 y 65,000 unidades, con una confiabilidad del 95%.