Analizar la información de las ventas de 2016 a 2019 de productos de la familia Coca COla en algunos de los establecimientos de la zona metropolitana de gualajara en los que se implementó el proyecto siglo xxi de arca continental.
Librerias
library(readxl)
Base de datos
bd <- read_excel("/Users/pedrovillanueva/Downloads/Datos Arca Continental Original.xlsx") # Importamos la base de datos
## 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
head(bd) # Confirmamos que nuestra base de datos si se subio de manera correcta y vemos los primeros regristros.
## # A tibble: 6 × 25
## 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
## # ℹ 18 more variables: `Tamaño Cte Industria` <chr>, `Segmento Det` <chr>,
## # Marca <chr>, Presentacion <chr>, Tamaño <chr>, Retornable_NR <chr>,
## # Enero <dbl>, Febrero <dbl>, Marzo <dbl>, Abril <dbl>, Mayo <dbl>,
## # Junio <dbl>, Julio <dbl>, Agosto <dbl>, Septiembre <dbl>, Octubre <dbl>,
## # Noviembre <dbl>, Diciembre <dbl>
Vemos el tipo de dato de cada variable
sapply(bd, class)
## ID Año Territorio
## "numeric" "numeric" "character"
## Sub Territorio CEDI Cliente
## "character" "character" "character"
## Nombre Tamaño Cte Industria Segmento Det
## "character" "character" "character"
## Marca Presentacion Tamaño
## "character" "character" "character"
## Retornable_NR Enero Febrero
## "character" "numeric" "numeric"
## Marzo Abril Mayo
## "numeric" "numeric" "numeric"
## Junio Julio Agosto
## "numeric" "numeric" "numeric"
## Septiembre Octubre Noviembre
## "numeric" "numeric" "numeric"
## Diciembre
## "numeric"
summary(bd)
## 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
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
count(bd,Territorio, sort = TRUE)
## # A tibble: 2 × 2
## Territorio n
## <chr> <int>
## 1 Guadalajara 466508
## 2 Territorio 1
# count(bd, CEDI, sort = TRUE)
# count(bd, Cliente, sort = TRUE)
# count(bd, Nombre, sort = TRUE)
# count(bd, Marca, sort = TRUE)
# count(bd, Presentacion, sort = TRUE)
# count(bd, Tamaño, sort = TRUE)
# count(bd, Retornable_NR, sort = TRUE)
observaciones: 1. Eliminar rengol 184065 qu tinee. titulos en lugar de datos. 2. Cambiar formatos ( de enro a diciember) de caracter a enero
Eliminar el registros
bd <- bd[-184065,]
Cambiar tipo de dato
bd$Enero <- as.integer(bd$Enero)
bd$Febero <- as.integer(bd$Febrero)
bd$Marzo <- as.integer(bd$Marzo)
bd$Abril <- as.integer(bd$Abril)
bd$Mayo <- as.integer(bd$Mayo)
bd$Junio <- as.integer(bd$Junio)
bd$Julio <- as.integer(bd$Julio)
bd$Agosto <- as.integer(bd$Agosto)
bd$Septiembre <- as.integer(bd$Septiembre)
bd$Octubre <- as.integer(bd$Octubre)
bd$Noviembre <- as.integer(bd$Noviembre)
bd$Diciembre <- as.integer(bd$Diciembre)
summary(bd)
## 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.00 Min. : -11.00 Min. : -32.00
## Class :character 1st Qu.: 1.00 1st Qu.: 1.00 1st Qu.: 1.00
## Mode :character Median : 2.00 Median : 2.00 Median : 3.00
## Mean : 9.91 Mean : 9.57 Mean : 11.18
## 3rd Qu.: 6.00 3rd Qu.: 6.00 3rd Qu.: 6.00
## Max. :5333.00 Max. :4995.00 Max. :5636.00
## NA's :233480 NA's :231213 NA's :227420
## Abril Mayo Junio Julio
## Min. : -70.00 Min. :-106.00 Min. :-211.00 Min. : -60.00
## 1st Qu.: 1.00 1st Qu.: 1.00 1st Qu.: 1.00 1st Qu.: 1.00
## Median : 3.00 Median : 3.00 Median : 3.00 Median : 2.00
## Mean : 11.53 Mean : 12.58 Mean : 12.03 Mean : 11.58
## 3rd Qu.: 6.00 3rd Qu.: 7.00 3rd Qu.: 6.00 3rd Qu.: 6.00
## Max. :6164.00 Max. :6759.00 Max. :6033.00 Max. :6735.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
## 1st Qu.: 1.00 1st Qu.: 1.0 1st Qu.: 1.0 1st Qu.: 1
## Median : 3.00 Median : 3.0 Median : 3.0 Median : 3
## Mean : 11.81 Mean : 13.1 Mean : 13.4 Mean : 13
## 3rd Qu.: 6.00 3rd Qu.: 7.0 3rd Qu.: 7.0 3rd Qu.: 6
## Max. :6065.00 Max. :6509.0 Max. :6326.0 Max. :5319
## NA's :220242 NA's :337314 NA's :338386 NA's :338460
## Diciembre Febero
## Min. : -28.0 Min. : -11.00
## 1st Qu.: 1.0 1st Qu.: 1.00
## Median : 3.0 Median : 2.00
## Mean : 14.4 Mean : 9.57
## 3rd Qu.: 7.0 3rd Qu.: 6.00
## Max. :6182.0 Max. :4995.00
## NA's :341855 NA's :231213
observaciones: 3. Tenemos na en las columnas de meses 4. tenemos cantidades negativas 5. No tenemos ventas por año 6. Cantidades máximas muy elevadas
Imputación de datos
# Remplazamos todos los NA por ceros dado que no hubo ventas sobre ese cliente durante ese mes
bd$Enero <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Febrero <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Marzo <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Abril <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Mayo <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Junio <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Julio <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Agosto <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Septiembre <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Octubre <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Noviembre <- replace(bd$Enero, is.na(bd$Enero), 0)
bd$Diciembre <- replace(bd$Enero, is.na(bd$Enero), 0)
# Confirmamos que no hay NA
sum(is.na(bd)) # Vemos que no hay valores nulos
## [1] 231213
bd$Ventas <- bd$Enero + bd$Febrero +bd$Marzo+bd$Abril+bd$Mayo+bd$Junio+bd$Julio+bd$Agosto+bd$Septiembre+bd$Octubre+bd$Noviembre+bd$Diciembre
summary(bd)
## 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. : -19.000 Min. : -19.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.951 Mean : 4.951
## 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 2.000
## Max. :5333.000 Max. :5333.000 Max. :5333.000
##
## Abril Mayo Junio Julio
## Min. : -19.000 Min. : -19.000 Min. : -19.000 Min. : -19.000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 0.000 Median : 0.000 Median : 0.000 Median : 0.000
## Mean : 4.951 Mean : 4.951 Mean : 4.951 Mean : 4.951
## 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 2.000
## Max. :5333.000 Max. :5333.000 Max. :5333.000 Max. :5333.000
##
## Agosto Septiembre Octubre Noviembre
## Min. : -19.000 Min. : -19.000 Min. : -19.000 Min. : -19.000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 0.000 Median : 0.000 Median : 0.000 Median : 0.000
## Mean : 4.951 Mean : 4.951 Mean : 4.951 Mean : 4.951
## 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 2.000 3rd Qu.: 2.000
## Max. :5333.000 Max. :5333.000 Max. :5333.000 Max. :5333.000
##
## Diciembre Febero Ventas
## Min. : -19.000 Min. : -11.00 Min. : -228.00
## 1st Qu.: 0.000 1st Qu.: 1.00 1st Qu.: 0.00
## Median : 0.000 Median : 2.00 Median : 0.00
## Mean : 4.951 Mean : 9.57 Mean : 59.42
## 3rd Qu.: 2.000 3rd Qu.: 6.00 3rd Qu.: 24.00
## Max. :5333.000 Max. :4995.00 Max. :63996.00
## NA's :231213
Grafica de caja y bigotes
boxplot(bd$Enero, horizontal = TRUE)
boxplot(bd$Agosto,horizontal = TRUE)
library(ggplot2)
ggplot(bd, aes(x = Año, y = Ventas)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
ggplot(bd, aes(x = Año, y = Ventas, colour=`Tamaño Cte Industria`)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
bd2 <- bd %>% filter(`Tamaño Cte Industria`=="Extra Grande")
ggplot(bd2, aes(x = Año, y = Ventas, colour=`Tamaño Cte Industria`)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
bd3 <- bd %>% filter(`Tamaño Cte Industria`=="Grande")
ggplot(bd3, aes(x = Año, y = Ventas, colour=`Tamaño Cte Industria`)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
bd4 <- bd %>% filter(`Tamaño Cte Industria`=="Micro")
ggplot(bd4, aes(x = Año, y = Ventas, colour=`Tamaño Cte Industria`)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
bd5 <- bd %>% filter(`Tamaño Cte Industria`=="Pequeño")
ggplot(bd5, aes(x = Año, y = Ventas, colour=`Tamaño Cte Industria`)) +
geom_bar(stat="identity") +
labs(
title= "ventas por año",
subtitle= "caso arca continental"
)
3¿Cuál es el comportamiento observado de las unidades vendidas por mes de cada una de las marcas, independientemente de sus r. espectivas presentaciones? Respuesta: la marca más vendida es Coca-Cola, con una tendencia de ventas positiva en 2019. La marca sprite tambien muestra un crecimiento continuo a través de los años
bd6 <- bd %>% filter(
Marca== "Coca-Cola"
)
ggplot(bd6,aes(x=Año, y=Ventas, colour="Tamaño Cte Industria")) +
geom_bar(stat = "Identity") +
labs(
title = "Ventas por año de Coca Cola",
subtitle = "Caso Arca Continental"
)
bd7 <- bd %>% filter(Marca=="Sprite")
ggplot(bd7, aes(x=Año, y= Ventas, colour="Tamaño Cte Industria")) +
geom_bar(stat = "Identity") +
labs(
title = "Ventas por año de Sprite",
subtitle = "Caso Arca Continental"
)
bd8 <- bd %>% filter(Retornable_NR=="Retornable")
ggplot(bd8, aes(x=Año, y= Ventas, colour="Tamaño Cte Industria")) +
geom_bar(stat = "Identity") +
labs(
title = "Ventas por año de envases retornables",
subtitle = "Caso Arca Continental"
)
# Cambiar el nombre de la columna
colnames(bd)[colnames(bd) == "Segmento Det"] <- "Segmento.Det"
bd9 <- bd %>% filter( Segmento.Det=="Agua Purificada" | Segmento.Det=="Isotónicos Regular" | Segmento.Det=="Colas Regular")
ggplot(bd9, aes(x=Año, y= Ventas, fill=Segmento.Det)) +
geom_bar(position="dodge", stat = "Identity") +
labs(
title = "Ventas por año",
subtitle = "Caso Arca Continental"
)
bd10 <- bd %>% filter(Segmento.Det=="Agua Purificada" | Segmento.Det=="Colas Regular")
ggplot(bd10, aes(x=Año, y= Ventas, fill=Segmento.Det)) +
geom_bar(position="dodge", stat = "Identity") +
labs(
title = "Ventas por año",
subtitle = "Caso Arca Continental"
)
bd11 <- bd %>% filter(Marca=="Coca-Cola" & Presentacion=="500 ml NR Vidrio")
bd12 <- aggregate(Ventas ~ Año, bd11, sum)
bd12$Año <- as.integer(bd12$Año)
regresion <- lm(Ventas ~ Año, data=bd12)
summary(regresion)
##
## Call:
## lm(formula = Ventas ~ Año, data = bd12)
##
## Residuals:
## 1 2 3 4
## 8472 8748 -42912 25692
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -162637908 32841416 -4.952 0.0384 *
## Año 80784 16278 4.963 0.0383 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 36400 on 2 degrees of freedom
## Multiple R-squared: 0.9249, Adjusted R-squared: 0.8873
## F-statistic: 24.63 on 1 and 2 DF, p-value: 0.03829
#Ecuacion de la recta y = -54,970,595 + 27,433*Año
datos <- data.frame(Año=2020)
predict(regresion,datos)
## 1
## 545772