Jimena Miguel | Vanessa Elizondo | Ricardo Galicia | José Luis Elizondo | Daniela Cárdenas

Actividad 2.1

Importar base de datos

#file.choose()
base_de_datos<-read.csv("C:\\Users\\danyc\\OneDrive - Instituto Tecnologico y de Estudios Superiores de Monterrey\\Desktop\\Form\\Formdeliveryfinal3.csv" )

Instalacion de paquetes

library(foreign)
library(dplyr)        # data manipulation 
## 
## 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(forcats)      # to work with categorical variables
library(ggplot2)      # data visualization 
library(janitor)      # data exploration and cleaning 
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
#install.packages("Hmisc")
library(Hmisc)        # several useful functions for data analysis 
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
#install.packages("psych")
library(psych)        # functions for multivariate analysis 
## 
## Attaching package: 'psych'
## The following object is masked from 'package:Hmisc':
## 
##     describe
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
#install.packages("naniar")
library(naniar)       # summaries and visualization of missing values NAs
#install.packages("dlookr")
library(dlookr)  # summaries and visualization of missing values NAs
## 
## Attaching package: 'dlookr'
## The following object is masked from 'package:psych':
## 
##     describe
## The following object is masked from 'package:Hmisc':
## 
##     describe
## The following object is masked from 'package:base':
## 
##     transform
#install.packages("corrplot")
library(corrplot)     # correlation plots
## corrplot 0.92 loaded
#install.packages("jtools")
library(jtools)       # presentation of regression analysis 
## 
## Attaching package: 'jtools'
## The following object is masked from 'package:Hmisc':
## 
##     %nin%
#install.packages("lmtest")
library(lmtest)       # diagnostic checks - linear regression analysis 
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
#install.packages("car")
library(car)          # diagnostic checks - linear regression analysis
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
## The following object is masked from 'package:dplyr':
## 
##     recode
#install.packages("olsrr")
library(olsrr)        # diagnostic checks - linear regression analysis 
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
#install.packages("kableExtra")
library(kableExtra)   # HTML table attributes
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(tidyverse)
## Registered S3 methods overwritten by 'broom':
##   method            from  
##   tidy.glht         jtools
##   tidy.summary.glht jtools
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ tibble  3.1.8     ✔ purrr   0.3.4
## ✔ tidyr   1.2.0     ✔ stringr 1.4.1
## ✔ readr   2.1.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ psych::%+%()             masks ggplot2::%+%()
## ✖ psych::alpha()           masks ggplot2::alpha()
## ✖ tidyr::extract()         masks dlookr::extract()
## ✖ dplyr::filter()          masks stats::filter()
## ✖ kableExtra::group_rows() masks dplyr::group_rows()
## ✖ dplyr::lag()             masks stats::lag()
## ✖ car::recode()            masks dplyr::recode()
## ✖ purrr::some()            masks car::some()
## ✖ Hmisc::src()             masks dplyr::src()
## ✖ Hmisc::summarize()       masks dplyr::summarize()

Entender mi base de datos

  1. ¿Cuántas variables y cuantos registros tiene la base de datos? Se muestran 8 variables y 1440 registros dentro de la base de datos.
bd<-base_de_datos
summary(bd)
##      Target    Cliente             Vueltas      Plan.arrival   
##  Min.   :1   Length:1440        Min.   :1.00   Min.   : 0.000  
##  1st Qu.:1   Class :character   1st Qu.:1.00   1st Qu.: 0.000  
##  Median :1   Mode  :character   Median :1.50   Median : 4.000  
##  Mean   :1                      Mean   :1.75   Mean   : 6.625  
##  3rd Qu.:1                      3rd Qu.:2.25   3rd Qu.:10.750  
##  Max.   :1                      Max.   :3.00   Max.   :20.000  
##   Real.arrival    Real.departure     Diference           Fecha          
##  Min.   : 0.000   Min.   : 0.000   Min.   :-14.3500   Length:1440       
##  1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.:  0.0000   Class :character  
##  Median : 0.000   Median : 0.000   Median :  0.0000   Mode  :character  
##  Mean   : 3.823   Mean   : 4.142   Mean   :  0.3155                     
##  3rd Qu.: 8.000   3rd Qu.: 9.000   3rd Qu.:  0.8000                     
##  Max.   :23.500   Max.   :24.500   Max.   : 20.0000
str(bd)
## 'data.frame':    1440 obs. of  8 variables:
##  $ Target        : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Cliente       : chr  "PRINTEL " "MAHLE" "MAHLE" "MAHLE" ...
##  $ Vueltas       : int  1 1 2 3 1 1 2 3 1 1 ...
##  $ Plan.arrival  : int  16 8 9 20 0 0 0 0 16 8 ...
##  $ Real.arrival  : num  16 8 9 20 0 0 0 0 16 8 ...
##  $ Real.departure: num  19.3 8.55 10 21 0 0 0 0 18.1 9 ...
##  $ Diference     : num  3.3 0.55 1 1 0 0 0 0 2.1 1 ...
##  $ Fecha         : chr  "2/1/2022" "2/1/2022" "2/1/2022" "2/1/2022" ...

Count de Variables y Escalas

  1. Clasifica cada variable en cualitativa, cuantitativa discreta o cuantitativa continua.
Variable<-c("`Target`","`Cliente`","`Vueltas`","`Plan.arrival`","`Real.arrival`","`Real.departure`","`Diference`","`Fecha`")
Type<-c("quantiative (discrete)", "quantiative (continous)", "quantitative (continous)", "quantitative (continous)")
table<-data.frame(Variable,Type)
knitr::kable(table)
Variable Type
Target quantiative (discrete)
Cliente quantiative (continous)
Vueltas quantitative (continous)
Plan.arrival quantitative (continous)
Real.arrival quantiative (discrete)
Real.departure quantiative (continous)
Diference quantitative (continous)
Fecha quantitative (continous)
  1. Elige la escala de medición de cada variable.
variables <- c("`Target`","`Cliente`","`Vueltas`","`Plan.arrival`","`Real.arrival`","`Real.departure`","`Diference`","`Fecha`")
tipos <- c("cuantitativo (discreto)  ", "cualitativo  ", "cuantitativo (discreto)  ", "cuantitativo (continuo)  ", "cuantitativo (continuo)  ", "cuantitativo (continuo)  ", "cuantitativo (continuo)  ", "cualitativo  ")
escalas <- c("intervalo", "nominal", "razon", "razon", "razon", "razon", "razon", "ordinal")
table1 <- data.frame (variables, tipos, escalas)
knitr::kable(table1)
variables tipos escalas
Target cuantitativo (discreto) intervalo
Cliente cualitativo nominal
Vueltas cuantitativo (discreto) razon
Plan.arrival cuantitativo (continuo) razon
Real.arrival cuantitativo (continuo) razon
Real.departure cuantitativo (continuo) razon
Diference cuantitativo (continuo) razon
Fecha cualitativo ordinal

Limpieza de bases de datos

  1. Aplica al menos 2 técnicas de limpieza de bases de datos y explícalas brevemente, ¿por qué realizaste esas técnicas?

Las técnicas elegidas en nuestra limpia de datos se eligieron por las necesidades que presentaba la base y la utilidad o no que tenían nuestras variables

CONVERSION DE CARACTER A FECHA (TECNICA DE CONVERSION DE DATOS)

bd1<-bd
bd1$Fecha<- as.Date(bd1$Fecha, format= "%d/%m/%Y")
summary(bd1)
##      Target    Cliente             Vueltas      Plan.arrival   
##  Min.   :1   Length:1440        Min.   :1.00   Min.   : 0.000  
##  1st Qu.:1   Class :character   1st Qu.:1.00   1st Qu.: 0.000  
##  Median :1   Mode  :character   Median :1.50   Median : 4.000  
##  Mean   :1                      Mean   :1.75   Mean   : 6.625  
##  3rd Qu.:1                      3rd Qu.:2.25   3rd Qu.:10.750  
##  Max.   :1                      Max.   :3.00   Max.   :20.000  
##   Real.arrival    Real.departure     Diference            Fecha           
##  Min.   : 0.000   Min.   : 0.000   Min.   :-14.3500   Min.   :0022-01-13  
##  1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.:  0.0000   1st Qu.:0022-03-29  
##  Median : 0.000   Median : 0.000   Median :  0.0000   Median :0022-06-24  
##  Mean   : 3.823   Mean   : 4.142   Mean   :  0.3155   Mean   :0833-05-26  
##  3rd Qu.: 8.000   3rd Qu.: 9.000   3rd Qu.:  0.8000   3rd Qu.:2022-03-10  
##  Max.   :23.500   Max.   :24.500   Max.   : 20.0000   Max.   :2022-07-12
tibble(bd1)
## # A tibble: 1,440 × 8
##    Target Cliente    Vueltas Plan.arrival Real.arri…¹ Real.…² Difer…³ Fecha     
##     <int> <chr>        <int>        <int>       <dbl>   <dbl>   <dbl> <date>    
##  1      1 "PRINTEL "       1           16          16   19.3     3.3  2022-01-02
##  2      1 "MAHLE"          1            8           8    8.55    0.55 2022-01-02
##  3      1 "MAHLE"          2            9           9   10       1    2022-01-02
##  4      1 "MAHLE"          3           20          20   21       1    2022-01-02
##  5      1 "MAGNA"          1            0           0    0       0    2022-01-02
##  6      1 "VARROC"         1            0           0    0       0    2022-01-02
##  7      1 "VARROC"         2            0           0    0       0    2022-01-02
##  8      1 "VARROC"         3            0           0    0       0    2022-01-02
##  9      1 "PRINTEL "       1           16          16   18.1     2.1  2022-01-03
## 10      1 "MAHLE"          1            8           8    9       1    2022-01-03
## # … with 1,430 more rows, and abbreviated variable names ¹​Real.arrival,
## #   ²​Real.departure, ³​Diference

¿Cuantos N/A tengo en mi base de datos?

sum(is.na(bd1))
## [1] 0

Eliminar columnas

bd2<-bd1
bd2 <- subset(bd2, select =-c (Target))

Se elimina el target ya que no nos muestra una información detallada al darnos datos nulos de tener un 1 en todos lados.

LIMPIEZA POR METODO ESTADISTICO

bd3<-bd2
boxplot(bd3$Plan.arrival, horizontal=TRUE)

boxplot(bd3$Real.arrival, horizontal=TRUE)

boxplot(bd3$Real.departure, horizontal=TRUE)

boxplot(bd3$Diference, horizontal=TRUE)

Agregar columna de promedio

bd3$Promedio_real_arrival<- mean(bd3$Real.arrival)

Notas:

Se muestra que la diferencia de nuestros arrivals no es mucha, pero habría que revisar si el promedio total nos ayudaría. se agrego una columna de promedio general de nuestros arrivals reales.

Exportar base de datos

bd_limpia<-bd3
write.csv(bd_limpia, file="formbaselimpia.csv", row.names = FALSE)

Conclusión

Para esta actividad, pudimos limpiar la base de datos que tiene Form al modificarla al 100% para poder acomodar los requerimientos que tiene R para insertar las bases y que hagan sentido a la hora de trabajarlo.

Para esta base de datos ahora lo que nos permitirá lograr es hacer gráficas y tablas para detallar y mostrar la información importante de nuestra base.

Actividad 2.2

Exportar la base de datos

#file.choose()
datoslimpios<-read.csv("C:\\Users\\Danyc\\OneDrive - Instituto Tecnologico y de Estudios Superiores de Monterrey\\Desktop\\Form\\formbaselimpia.csv" )

Tabla de Frecuencia

#install.packages('epiDisplay')
library(epiDisplay)
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:olsrr':
## 
##     cement
## The following object is masked from 'package:dplyr':
## 
##     select
## Loading required package: nnet
## 
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:lmtest':
## 
##     lrtest
## The following object is masked from 'package:jtools':
## 
##     summ
## The following objects are masked from 'package:psych':
## 
##     alpha, cs, lookup
## The following object is masked from 'package:lattice':
## 
##     dotplot
## The following object is masked from 'package:ggplot2':
## 
##     alpha
tab1(datoslimpios$Diference, sort.group = "decreasing", cum.percent = TRUE) 

## datoslimpios$Diference : 
##         Frequency Percent Cum. percent
## 0            1014    70.4         70.4
## 1             192    13.3         83.8
## 1.1            20     1.4         85.1
## 1.05           17     1.2         86.3
## 1.2            16     1.1         87.4
## 0.5            14     1.0         88.4
## 1.15           11     0.8         89.2
## 0.9             8     0.6         89.7
## 0.4             8     0.6         90.3
## 1.5             7     0.5         90.8
## 0.8             7     0.5         91.2
## 0.55            7     0.5         91.7
## 2               6     0.4         92.2
## 1.8             6     0.4         92.6
## 1.3             6     0.4         93.0
## 0.3             6     0.4         93.4
## 1.4             5     0.3         93.8
## 1.25            5     0.3         94.1
## 0.95            5     0.3         94.4
## 0.2             5     0.3         94.8
## 1.45            4     0.3         95.1
## 1.35            3     0.2         95.3
## 0.45            3     0.2         95.5
## 0.35            3     0.2         95.7
## 0.1             3     0.2         95.9
## 3.1             2     0.1         96.0
## 2.6             2     0.1         96.2
## 2.38            2     0.1         96.3
## 2.15            2     0.1         96.5
## 1.6             2     0.1         96.6
## 1.03            2     0.1         96.7
## 0.85            2     0.1         96.9
## 0.7             2     0.1         97.0
## 0.6             2     0.1         97.2
## 0.15            2     0.1         97.3
## 4.4             1     0.1         97.4
## 4               1     0.1         97.4
## 3.3             1     0.1         97.5
## 3.05            1     0.1         97.6
## 20              1     0.1         97.6
## 2.85            1     0.1         97.7
## 2.52            1     0.1         97.8
## 2.5             1     0.1         97.8
## 2.4             1     0.1         97.9
## 2.35            1     0.1         98.0
## 2.3             1     0.1         98.1
## 2.27            1     0.1         98.1
## 2.2             1     0.1         98.2
## 2.1             1     0.1         98.3
## 2.05            1     0.1         98.3
## 1.95            1     0.1         98.4
## 1.9             1     0.1         98.5
## 1.88            1     0.1         98.5
## 1.85            1     0.1         98.6
## 1.74            1     0.1         98.7
## 1.73            1     0.1         98.8
## 1.7             1     0.1         98.8
## 1.66            1     0.1         98.9
## 1.65            1     0.1         99.0
## 1.55            1     0.1         99.0
## 1.14            1     0.1         99.1
## 1.13            1     0.1         99.2
## 1.07            1     0.1         99.2
## 1.04            1     0.1         99.3
## 1.01            1     0.1         99.4
## 0.99            1     0.1         99.4
## 0.98            1     0.1         99.5
## 0.75            1     0.1         99.6
## 0.47            1     0.1         99.7
## 0.43            1     0.1         99.7
## 0.34            1     0.1         99.8
## 0.25            1     0.1         99.9
## -14.35          1     0.1         99.9
## -12.15          1     0.1        100.0
##   Total      1440   100.0        100.0
tab1(datoslimpios$Real.arrival, sort.group = "decreasing", cum.percent = TRUE)

## datoslimpios$Real.arrival : 
##         Frequency Percent Cum. percent
## 0            1009    70.1         70.1
## 8             100     6.9         77.0
## 20             83     5.8         82.8
## 9              81     5.6         88.4
## 18             11     0.8         89.2
## 9.4            10     0.7         89.9
## 15              9     0.6         90.5
## 18.2            8     0.6         91.0
## 16              7     0.5         91.5
## 9.5             6     0.4         91.9
## 9.2             6     0.4         92.4
## 9.1             6     0.4         92.8
## 10              6     0.4         93.2
## 9.15            5     0.3         93.5
## 15.1            5     0.3         93.9
## 16.2            4     0.3         94.2
## 9.3             3     0.2         94.4
## 15.2            3     0.2         94.6
## 9.45            2     0.1         94.7
## 9.26            2     0.1         94.9
## 9.12            2     0.1         95.0
## 9.08            2     0.1         95.1
## 8.1             2     0.1         95.3
## 8.05            2     0.1         95.4
## 7.35            2     0.1         95.6
## 7.3             2     0.1         95.7
## 6               2     0.1         95.8
## 23.3            2     0.1         96.0
## 20.2            2     0.1         96.1
## 20.1            2     0.1         96.2
## 19.2            2     0.1         96.4
## 18.4            2     0.1         96.5
## 18.3            2     0.1         96.7
## 16.4            2     0.1         96.8
## 15.3            2     0.1         96.9
## 13              2     0.1         97.1
## 9.35            1     0.1         97.2
## 9.25            1     0.1         97.2
## 9.17            1     0.1         97.3
## 9.11            1     0.1         97.4
## 9.05            1     0.1         97.4
## 8.52            1     0.1         97.5
## 8.45            1     0.1         97.6
## 7.45            1     0.1         97.6
## 7.34            1     0.1         97.7
## 23.5            1     0.1         97.8
## 23.2            1     0.1         97.8
## 23.15           1     0.1         97.9
## 23              1     0.1         98.0
## 22.4            1     0.1         98.1
## 22.08           1     0.1         98.1
## 21.15           1     0.1         98.2
## 21.1            1     0.1         98.3
## 21.05           1     0.1         98.3
## 20.4            1     0.1         98.4
## 20.3            1     0.1         98.5
## 20.15           1     0.1         98.5
## 20.05           1     0.1         98.6
## 19.48           1     0.1         98.7
## 19.15           1     0.1         98.8
## 19.1            1     0.1         98.8
## 18.5            1     0.1         98.9
## 18.35           1     0.1         99.0
## 18.15           1     0.1         99.0
## 18.1            1     0.1         99.1
## 18.05           1     0.1         99.2
## 17.3            1     0.1         99.2
## 17              1     0.1         99.3
## 15.45           1     0.1         99.4
## 15.4            1     0.1         99.4
## 15.16           1     0.1         99.5
## 14              1     0.1         99.6
## 13.4            1     0.1         99.7
## 11.37           1     0.1         99.7
## 11              1     0.1         99.8
## 10.42           1     0.1         99.9
## 10.4            1     0.1         99.9
## 10.05           1     0.1        100.0
##   Total      1440   100.0        100.0

Notas:

Viendo el gráfico de distribución se pueden ver las frecuencias en las diferencias, se ve una mayor parte en el número 0, lo cual nos indica un buen desarrollo en delivery.

Gráficos de datos Cualitativos y Cuantitativos (2)

ggplot(datoslimpios, aes(x = Vueltas, y = Real.departure, color = Cliente)) +
  geom_boxplot()

Notas:

La media de Mahle en este caso es superior en las partidas de sus productos, lo cual suena a que la partida podría tener un sentido de tardanza en la producción más que en entregas.

bd4<-datoslimpios
bd4$year<- strftime(bd4$Fecha, "%Y")
bd4$mes<- strftime(bd4$Fecha, "%m")

bd5 <- aggregate(Real.arrival ~ mes+year,
                 bd4,
                 FUN = sum)
ggplot(bd5, aes(x=mes, y=Real.arrival)) +
  geom_bar(stat="identity", color="blue", fill="white")

###Observación: En este gráfico se sumaron todos los arrivals reales por mes para ver más que nada como es el crecimiento de cada mes en llegadas de empaques, podemos ver que el mes com más retrasos fue enero del 2022

Gráficos de dispersión (2)

library(ggplot2)
ggplot(datoslimpios, aes(x=Diference, y=Cliente, shape=cyl, color=cyl)) +
  geom_point(shape=18, color="orange")

Notas:

En esta tabla se puede visualizar la diferencia de arrivals que hay dentro del “Performance” el cual podemos ver en el scatter que con mayor diferencia se encuentran Printel y Mahle por el movimiento de los puntos.

ggplot(datoslimpios, aes(x=Vueltas, y=Real.arrival, shape=cyl, color=cyl)) +
  geom_point(shape=18, color="orange")

Notas:

Aquí se puede observar que en promedio, la tercera vuelta es la que tardó más en llegar a comparación de la primera y la segunda vuelta lo cual nos dice que no se esta haciendo tan eficiente este proceso.

Propuestas

Despúes de la recabación de datos, se analizaron y se crearon dos propuestas: 1. Crear un plan de entregas con menos de dos vueltas ya que se mostró menos efectiva la tercera marcando más tardanzas a lo largo del análisis. 2. Crear un plan mensual con KPI´s de rapidez de entregas para ver el flujo por mes de lo que están tardando y ver las acciones especificas para mitigar ese retraso.