ESTADÍSTICA DESCRIPTIVA
CONTEXTO ANÁLSIS DE LOS RECIBOS DE LUZ DE UNA CASA EN CALIFORNIA 2006
INSTALAR LOS PAQUETES
#install.packages("modest")
#install.packages("qcc")
#install.packages("Pareto")
LLAMAR A LAS LIBRERÍAS
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(modest)
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(qcc)
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
ACTIVIDAD 3.1 MEDIDAS DE TENDENCIA CENTRAL Y MEDIDAS DE DISPERSIÓN
IMPORTAR LA BASE DE DATOS
library(readxl)
poblacion <- read_excel("~/R LUISA/poblacion.xlsx")
View(poblacion)
library(readxl)
muestra <- read_excel("~/R LUISA/muestra.xlsx")
View(muestra)
TAMAÑO DE LA POBLACIÓN (N) LENGTH: cuantos valores tiene un vector
N<-length(poblacion$PAGO)
View(N)
TAMAÑO DE LA MUESTRA (n)
n<-length(muestra$PAGO)
View(n)
MEDIDAS DE TENDENCIA CENTRAL Permiten conocer el valor al que tiende el conjunto de datos.
PROMEDIO Valor que se obtiene al sumar todos los datos y dividirlos entre la cantidad total de datos.
MEDIA POBLACIONAL (MIU)
media_poblacional<- mean(poblacion$PAGO)
View(media_poblacional)
MEDIA MUESTRAL (X BARRA)
media_muestral<- mean(muestra$PAGO)
View(media_muestral)
MEDIANA Valor que ocupa el lugar central de todos los datos cuando éstos están ordenados.
MEDIANA POBLACIONAL
mediana_poblacional<- median(poblacion$PAGO)
View(mediana_poblacional)
MEDIANA MUESTRAL
mediana_muestral<- median(muestra$PAGO)
View(mediana_muestral)
RESUMEN
summary(poblacion)
## MES PAGO
## Length:12 Min. :162.6
## Class :character 1st Qu.:203.5
## Mode :character Median :228.6
## Mean :245.0
## 3rd Qu.:293.5
## Max. :343.5
summary(muestra)
## MES PAGO
## Length:5 Min. :187.2
## Class :character 1st Qu.:219.4
## Mode :character Median :230.5
## Mean :249.4
## 3rd Qu.:266.6
## Max. :343.5
MODA FUNCIÓN PARA CALCULAR LA MODA
moda = function(x){
ux = unique(x)
ux[which.max((tabulate(match(x, ux))))]
}
Si nunguno de los datos se repite, la función coloca el primer valor en lugar de marcar error. MODA POBLACIONAL
moda_poblacional = moda(poblacion$PAGO)
moda_poblacional
## [1] 266.63
MODA MUESTRAL
moda_muestral <- moda(muestra$PAGO)
moda_muestral
## [1] 266.63
RELACIÓN ENTRE LA MEDIA, MEDIANA Y MODA si la media = mediana = moda, los datos tienen una distribución simétrica si la media < mediana < moda, los datos tienen sesgos NEGATIVO si la moda < mediana < media, los datos tienen sesgos POSITIVO
MEDIDAS DE TENDENCIA CENTRAL
mtc_poblacional <- c(media_poblacional,mediana_poblacional,moda_poblacional)
names(mtc_poblacional)<-c("media_poblacional","mediana_poblacional","moda_poblacional")
NAMES pone a cada variable un nombre
mtc_poblacional <- sort(mtc_poblacional)
View(mtc_poblacional)
SORT es acomodar #HITS LA POBLACIÓN TIENE SESGO POSITIVO
hist(poblacion$PAGO)
MEDIDAS DE DISPERSIÓN Miden que tan esparcidos se encuentran los datos
RANGO Intervalo o diferencia entre el valor máximo y el mínimo, pero no su diferencia
rango_poblacional<-max(poblacion$PAGO)-min(poblacion$PAGO)
View(rango_poblacional)
rango_muestral<-max(muestra$PAGO)-min(muestra$PAGO)
View(rango_muestral)
VARIANZA Promedio elevado al cuadrado de las desviaciones individuales de cada observación con respecto a la media de una distribución. Si es población, se divide entre N; si es muestra se divide entre n-1
VARIANZA POBLACIONAL
varianza_poblacional<- var(poblacion$PAGO)*(N-1)/N
View(varianza_poblacional)
VARIANZA MUESTRAL
varianza_muestral<- var(muestra$PAGO)
View(varianza_muestral)
DESVIACIÓN ESTÁNDAR Raíz cuadrada de la varianza
DESVIACIÓN ESTÁNDAR POBLACIONAL (SIGMA)
desviacion_estandar_poblacional<- sqrt(varianza_poblacional)
View(desviacion_estandar_poblacional)
DESVIACIÓN ESTÁNDAR MUESTRAL
desviacion_estandar_muestral<- sqrt(varianza_muestral)
View(desviacion_estandar_muestral)
sodio<- c(260,300,320,330,340,340,520)
boxplot(sodio, horizontal =TRUE)
ACTIVIDAD 2 GRÁFICOS ESTADÍSTICOS
CONTEXTO, EMPRESA CON 5 TIENDAS DE ABARROTES EN DISTINTAS CIUDADES DE MEX
LLAMAR A LAS LIBRERÍAS Previamente se instalaron al inicio del algoritmo.
IMPORTAR BASE DE DATOS
library(readr)
Abarrotes_Ventas <- read_csv("C:\\Users\\Chuwi\\Documents\\R LUISA\\Abarrotes_Ventas.csv")
## Rows: 200620 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): vcClaveTienda, DescGiro, Fecha, Marca, Fabricante, Producto, Nomb...
## dbl (7): Codigo Barras, PLU, Precio, Ult.Costo, Unidades, F.Ticket, Mts 2
## time (3): Hora, Hora inicio, Hora cierre
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(Abarrotes_Ventas)
CONOCER LOS DATOS
summary(Abarrotes_Ventas)
## vcClaveTienda DescGiro Codigo Barras PLU
## Length:200620 Length:200620 Min. :8.347e+05 Min. : 1.00
## Class :character Class :character 1st Qu.:7.501e+12 1st Qu.: 1.00
## Mode :character Mode :character Median :7.501e+12 Median : 1.00
## Mean :5.950e+12 Mean : 2.11
## 3rd Qu.:7.501e+12 3rd Qu.: 1.00
## Max. :1.750e+13 Max. :30.00
## NA's :199183
## Fecha Hora Marca Fabricante
## Length:200620 Length:200620 Length:200620 Length:200620
## Class :character Class1:hms Class :character Class :character
## Mode :character Class2:difftime Mode :character Mode :character
## Mode :numeric
##
##
##
## Producto Precio Ult.Costo Unidades
## Length:200620 Min. :-147.00 Min. : 0.38 Min. : 0.200
## Class :character 1st Qu.: 11.00 1st Qu.: 8.46 1st Qu.: 1.000
## Mode :character Median : 16.00 Median : 12.31 Median : 1.000
## Mean : 19.42 Mean : 15.31 Mean : 1.262
## 3rd Qu.: 25.00 3rd Qu.: 19.23 3rd Qu.: 1.000
## Max. :1000.00 Max. :769.23 Max. :96.000
##
## F.Ticket NombreDepartamento NombreFamilia NombreCategoria
## Min. : 1 Length:200620 Length:200620 Length:200620
## 1st Qu.: 33967 Class :character Class :character Class :character
## Median :105996 Mode :character Mode :character Mode :character
## Mean :193994
## 3rd Qu.:383009
## Max. :450040
##
## Estado Mts 2 Tipo ubicación Giro
## Length:200620 Min. :47.0 Length:200620 Length:200620
## Class :character 1st Qu.:53.0 Class :character Class :character
## Mode :character Median :60.0 Mode :character Mode :character
## Mean :56.6
## 3rd Qu.:60.0
## Max. :62.0
##
## Hora inicio Hora cierre
## Length:200620 Length:200620
## Class1:hms Class1:hms
## Class2:difftime Class2:difftime
## Mode :numeric Mode :numeric
##
##
##
COUNT CONOCER LOS DATOS DE CIERTAS COLUMNAS (TODAS LAS QUE NO SON NÚMEROS)
count(Abarrotes_Ventas,vcClaveTienda, soft=TRUE)
## # A tibble: 5 × 3
## vcClaveTienda soft n
## <chr> <lgl> <int>
## 1 MX001 TRUE 96464
## 2 MX002 TRUE 6629
## 3 MX003 TRUE 4051
## 4 MX004 TRUE 83455
## 5 MX005 TRUE 10021
count(Abarrotes_Ventas,DescGiro, soft=TRUE)
## # A tibble: 3 × 3
## DescGiro soft n
## <chr> <lgl> <int>
## 1 Abarrotes TRUE 100515
## 2 Carnicería TRUE 83455
## 3 Depósito TRUE 16650
count(Abarrotes_Ventas,Marca, soft=TRUE)
## # A tibble: 540 × 3
## Marca soft n
## <chr> <lgl> <int>
## 1 1-2-3 (ABARROTES) TRUE 128
## 2 1-2-3 (LAVANDERíA) TRUE 173
## 3 3 EN 1 TRUE 6
## 4 5 ESTRELLAS TRUE 305
## 5 ABSOR SEC TRUE 224
## 6 ABUELITA TRUE 26
## 7 ACE TRUE 231
## 8 ACT II TRUE 329
## 9 ACTIVIA TRUE 37
## 10 ADES TRUE 6
## # ℹ 530 more rows
count(Abarrotes_Ventas,Fabricante, soft=TRUE)
## # A tibble: 241 × 3
## Fabricante soft n
## <chr> <lgl> <int>
## 1 3M MEXICO TRUE 12
## 2 ABASTECIMIENTOS PLáSTICOS Y ELéCTRICOS, TRUE 55
## 3 ABSORMEX S.A DE C.V TRUE 112
## 4 ACEITES GRASAS Y DERIVADOS TRUE 1016
## 5 ACT II TRUE 329
## 6 AJEMEX TRUE 159
## 7 AJEMONTERREY TRUE 129
## 8 ALEN TRUE 2698
## 9 ALIMENTOS CAPULLO TRUE 609
## 10 ALIMENTOS DEL FUERTE TRUE 2098
## # ℹ 231 more rows
count(Abarrotes_Ventas,NombreDepartamento, soft=TRUE)
## # A tibble: 9 × 3
## NombreDepartamento soft n
## <chr> <lgl> <int>
## 1 Abarrotes TRUE 198274
## 2 Bebes e Infantiles TRUE 1483
## 3 Carnes TRUE 1
## 4 Farmacia TRUE 255
## 5 Ferretería TRUE 377
## 6 Mercería TRUE 44
## 7 Papelería TRUE 74
## 8 Productos a Eliminar TRUE 8
## 9 Vinos y Licores TRUE 104
count(Abarrotes_Ventas,NombreFamilia, soft=TRUE)
## # A tibble: 51 × 3
## NombreFamilia soft n
## <chr> <lgl> <int>
## 1 Accesorios TRUE 146
## 2 Aceite TRUE 1483
## 3 Aderezos TRUE 1507
## 4 Alcohol TRUE 16
## 5 Alimentos TRUE 810
## 6 Alimentos a Granel TRUE 1
## 7 Alimentos para Mascotas TRUE 878
## 8 Analgésicos TRUE 1
## 9 Antigripal TRUE 57
## 10 Antiácido TRUE 1
## # ℹ 41 more rows
count(Abarrotes_Ventas,NombreCategoria, soft=TRUE)
## # A tibble: 174 × 3
## NombreCategoria soft n
## <chr> <lgl> <int>
## 1 Achiotes TRUE 127
## 2 Aderezo para Ensalada TRUE 55
## 3 Afeitado y Depilación TRUE 408
## 4 Aguas TRUE 2985
## 5 Aguas Saborizadas TRUE 2630
## 6 Aluminios y Envolturas TRUE 2
## 7 Antojitos Mexicanos TRUE 48
## 8 Aromatizantes de Ambiente TRUE 48
## 9 Arroz TRUE 2047
## 10 Artículos de Limpieza TRUE 26
## # ℹ 164 more rows
count(Abarrotes_Ventas,Estado, soft=TRUE)
## # A tibble: 5 × 3
## Estado soft n
## <chr> <lgl> <int>
## 1 Chiapas TRUE 4051
## 2 Jalisco TRUE 6629
## 3 Nuevo León TRUE 96464
## 4 Quintana Roo TRUE 10021
## 5 Sinaloa TRUE 83455
count(Abarrotes_Ventas,"Mts 2", soft=TRUE)
## # A tibble: 1 × 3
## `"Mts 2"` soft n
## <chr> <lgl> <int>
## 1 Mts 2 TRUE 200620
count(Abarrotes_Ventas,"Tipo ubicación", soft=TRUE)
## # A tibble: 1 × 3
## `"Tipo ubicación"` soft n
## <chr> <lgl> <int>
## 1 Tipo ubicación TRUE 200620
count(Abarrotes_Ventas,Giro, soft=TRUE)
## # A tibble: 2 × 3
## Giro soft n
## <chr> <lgl> <int>
## 1 Abarrotes TRUE 183970
## 2 Mini súper TRUE 16650
count(Abarrotes_Ventas,"Hora inicio", soft=TRUE)
## # A tibble: 1 × 3
## `"Hora inicio"` soft n
## <chr> <lgl> <int>
## 1 Hora inicio TRUE 200620
count(Abarrotes_Ventas,"Hora cierre", soft=TRUE)
## # A tibble: 1 × 3
## `"Hora cierre"` soft n
## <chr> <lgl> <int>
## 1 Hora cierre TRUE 200620
TABLA DE FRECUENCIAS
table(Abarrotes_Ventas$NombreDepartamento)
##
## Abarrotes Bebes e Infantiles Carnes
## 198274 1483 1
## Farmacia Ferretería Mercería
## 255 377 44
## Papelería Productos a Eliminar Vinos y Licores
## 74 8 104
table(Abarrotes_Ventas$Estado)
##
## Chiapas Jalisco Nuevo León Quintana Roo Sinaloa
## 4051 6629 96464 10021 83455
TABLAS CRUZADAS PARA ESTO SE INSTALA LA LIBRERÍA JANITOR,LA CUAL SE INSTALÓ HASTA ARRIBA
tabla1<- tabyl(Abarrotes_Ventas,vcClaveTienda,NombreDepartamento)
View(tabla1)
GRÁFICOS DE DATOS CUALITATIVOS
Abarrotes_Ventas$SUBTOTAL<-Abarrotes_Ventas$Precio*Abarrotes_Ventas$Unidades
ggplot(Abarrotes_Ventas,aes(x=vcClaveTienda, y=SUBTOTAL)) +
geom_bar(stat="identity")
DIAGRAMA DE PARETO EXTRAE EL SUBSET CIERTOS DATOS
tabla1<-subset(tabla1,select= c(vcClaveTienda,Abarrotes))
pareto.chart(tabla1$Abarrotes, xlab=tabla1$vcClaveTienda)
##
## Pareto chart analysis for tabla1$Abarrotes
## Frequency Cum.Freq. Percentage Cum.Percent.
## A 9.541000e+04 9.541000e+04 4.812028e+01 4.812028e+01
## D 8.223400e+04 1.776440e+05 4.147493e+01 8.959521e+01
## E 1.001400e+04 1.876580e+05 5.050587e+00 9.464579e+01
## B 6.590000e+03 1.942480e+05 3.323683e+00 9.796948e+01
## C 4.026000e+03 1.982740e+05 2.030523e+00 1.000000e+02
GRÁFICO DE PUNTOS O LÍNEAS
plot(Abarrotes_Ventas$Precio,Abarrotes_Ventas$Unidades,main="RELACIÓN ENTRE $ Y UNIDADES", xlab="Precio", ylab="Unidades")
GRÁFICA DE CAJAS Y BIGOTES
boxplot(Abarrotes_Ventas$Precio,horizontal = TRUE)
boxplot(Abarrotes_Ventas$Unidades,horizontal = TRUE)
#PROPUESTAS
#1.Realizar un BENCHMARK de la tienda NUEVO LEÓN y replicar mejores prácticas en las otras 4 tiendas.
#2. Se recomienda enfocarse hacía el giro de abarrotes