link="https://docs.google.com/spreadsheets/d/e/2PACX-1vSvSuHA3qbQkqdVuA5jxtFugohO0z2pyck69hB5SdjosPPaN9jWs_VTQmluvgieGXvltBIlFrTJKklPLnWcJ6g/pub?gid=1079099559&single=true&output=csv"

Para entregarle datos al objeto uso la función read.csv

datos=read.csv(link, stringsAsFactors = F,na.strings = "")
datos

Identificando los nombres de las variables, es decir de cada columna

names(datos)
##  [1] "ID"     "SEX"    "RACE"   "SES"    "SCTYP"  "LOCUS"  "CONCPT"
##  [8] "MOT"    "RDG"    "WRTG"   "MATH"   "SCI"    "CIV"

Identifico el tipo de variables: número, texto o factor

str(datos)
## 'data.frame':    600 obs. of  13 variables:
##  $ ID    : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ SEX   : chr  "HOMBRE" "MUJER" "HOMBRE" "HOMBRE" ...
##  $ RACE  : chr  "ASIATICO" "ASIATICO" "ASIATICO" "ASIATICO" ...
##  $ SES   : chr  "ALTO" "ALTO" "ALTO" "MEDIO" ...
##  $ SCTYP : chr  "PUBLICA" "PUBLICA" "PUBLICA" "PUBLICA" ...
##  $ LOCUS : num  0.29 -0.42 0.71 0.06 0.22 0.46 0.44 0.68 0.06 0.05 ...
##  $ CONCPT: num  0.88 0.03 0.03 0.03 -0.28 0.03 -0.47 0.25 0.56 0.15 ...
##  $ MOT   : num  0.67 0.33 0.67 0 0 0 0.33 1 0.33 1 ...
##  $ RDG   : num  33.6 46.9 41.6 38.9 36.3 49.5 62.7 44.2 46.9 44.2 ...
##  $ WRTG  : num  43.7 35.9 59.3 41.1 48.9 46.3 64.5 51.5 41.1 49.5 ...
##  $ MATH  : num  40.2 41.9 41.9 32.7 39.5 46.2 48 36.9 45.3 40.5 ...
##  $ SCI   : num  39 36.3 44.4 41.7 41.7 41.7 63.4 49.8 47.1 39 ...
##  $ CIV   : num  40.6 45.6 45.6 40.6 45.6 35.6 55.6 55.6 55.6 50.6 ...

Parte 1: Explorando variables nominales

table(datos$RACE)
## 
## ASIATICO   BLANCO  HISPANO    NEGRO 
##       71       34      437       58

Tabla de frecuencias

library(questionr)
library(magrittr)
NomDf=freq(datos$RACE,total = F,sort = 'dec',exclude = c(NA)) %>% data.frame()
NomDf=data.frame(variable=row.names(NomDf),NomDf,row.names = NULL)
NomDf

Gráfico

library(ggplot2)

base = ggplot(data=NomDf,aes(x=variable,y=n)) 

bar1 = base + geom_bar(stat='identity') 

bar1

Tabla en orden

bar1 = bar1 + scale_x_discrete(limits = NomDf$variable)
bar1

Ahora agrego títulos que complementen a mi gráfico de barras

text1="¿Qué acción es mas común?"
text2="Acción"
text3="Conteo"
text4="Fuente: Clase 2"

bar2= bar1 + labs(title=text1,
                      x =text2, 
                      y = text3,
                      caption = text4) 
bar2

Cambios más detallados

bar2 + theme_classic() + 
            theme(plot.title = element_text(hjust = 0.2,size=15), # centrar y agrandar
                  plot.caption = element_text(hjust = 3), # a la derecha
                  axis.text.x = element_text(angle=45,hjust = 1)) # angulo

El gráfico de Pareto muestra dos medidas, los conteos y los porcentajes acumulados. Por tradición se trata de detectar que valores representan el 80%.

library(qcc)
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
pareto.chart(table(datos$RACE),cumperc = c(0,50,80,100))

##           
## Pareto chart analysis for table(datos$RACE)
##             Frequency  Cum.Freq. Percentage Cum.Percent.
##   HISPANO  437.000000 437.000000  72.833333    72.833333
##   ASIATICO  71.000000 508.000000  11.833333    84.666667
##   NEGRO     58.000000 566.000000   9.666667    94.333333
##   BLANCO    34.000000 600.000000   5.666667   100.000000

DATOS ESTADÍSTICOS

MODA: CUAL ES EL MÁS COMÚN

library(DescTools)
Mode(datos$RACE)
## [1] "HISPANO"

CONCENTRACIÓN: Herfindahl - Hirschman

dataTable=table(datos$RACE)

# * < 0.01 : indica que la moda no es significativa, las categorias tienen pesos similares.
# * < 0.15 : indica que la moda no es significativa, varias categorias tienen pesos similares.
# * entre 0.15 - 0.3: hay una moda.
# * > 0.3: La moda se diferencia de los demas

Herfindahl(dataTable)
## [1] 0.5570278

REPRESENTATIVIDAD EFECTIVA: LAAKSO - TAAGEPERA

1/sum(prop.table(dataTable)**2)
## [1] 1.795243

Parte 2: Explorando variables ordinales

table(datos$MATH)
## 
## 31.8 32.7 33.4 33.7 34.4 35.1 35.3   36 36.1 36.4 36.7 36.9 37.2 37.6 37.7 
##    1    1    1    3    1    2    4    2    2    1    1    4    1    2    5 
## 37.9 38.3 38.4 38.5 38.6 38.7 38.8 39.3 39.5 39.9 40.2 40.3 40.4 40.5 40.6 
##    1    1    5    1    6    3    1    1    3    1    6    7    2    1    1 
## 40.7 40.9   41 41.2 41.4 41.5 41.7 41.8 41.9   42 42.1 42.2 42.3 42.4 42.5 
##    1    2    8    7    2    1    2    1   11    1    2    2    1    1    1 
## 42.6 42.8 42.9   43 43.1 43.2 43.5 43.6 43.8 44.2 44.3 44.4 44.5 44.6 44.7 
##    3    7    4    1    2    1    3    3    3    2    4    1    6    1    2 
## 44.8   45 45.1 45.2 45.3 45.4 45.5 45.6 45.7 45.9 46.1 46.2 46.3 46.4 46.5 
##    2    1    4    2    1    4    3    2    2    7    5    7    3    1    1 
## 46.8 46.9 47.1 47.4 47.5 47.7 47.8   48 48.1 48.2 48.3 48.5 48.6 48.7 48.8 
##    3    3    7    1    1    3    3   12    2    1    1    3    1    3    3 
##   49 49.1 49.2 49.3 49.4 49.5 49.9 50.1 50.3 50.4 50.5 50.6 50.9   51 51.1 
##    1    1    2    1    3    7    2    1    6    6    2    4    1    1    6 
## 51.2 51.3 51.4 51.5 51.6 51.7 51.8 51.9   52 52.1 52.2 52.3 52.4 52.7 52.9 
##    1    8    3    1    2    1    4    3    3    1    6    1    3    1    6 
##   53 53.1 53.2 53.4 53.6 53.7 53.9 54.3 54.4 54.6 54.7 54.8 54.9 55.2 55.3 
##    7    2    1    1    2    5    5    2    3    7    1    3    1    1    6 
## 55.5 55.7 55.8 56.1 56.2 56.3 56.4 56.5 56.6 56.8 56.9   57 57.2 57.3 57.4 
##   13    2    1    1    4    7    2    2    2    3    3    4    4    1    2 
## 57.8 57.9   58 58.1 58.2 58.3 58.6 58.7 58.8 58.9 59.3 59.6 59.7 59.8   60 
##    1    6    1    5    1    1    1    1    5    3    1   10    1    2    1 
## 60.2 60.4 60.5 60.6 61.1 61.2 61.3 61.4 61.5 61.8 61.9   62 62.1 62.2 62.3 
##    1    3    5    1    1    5    1    5    1    1    2    1    2    1    5 
## 62.5 62.8   63 63.1 63.6 63.7 63.8   64 64.1 64.3 64.5 64.7 65.4 65.5 65.6 
##    1    4    5    2    1    2    3    5    2    1    4    3    4    1    1 
## 66.1 66.3 66.4   67 67.1 67.9   68 68.1 68.6 68.7 68.9 69.6 69.7 70.3 70.5 
##    2    3    3    3    4    2    3    1    1    1    2    3    1    1    4 
## 70.6 71.3 72.2 72.9 73.1 74.6 75.5 
##    1    4    5    1    1    3    2

Creando la tabla que usaremos:

OrdDf=freq(datos$MATH,total = F,exclude = c(NA)) %>% data.frame()
OrdDf=data.frame(variable=row.names(OrdDf),OrdDf,row.names = NULL)

# listo
OrdDf

Barras:

base=ggplot(data = OrdDf, aes(x=variable, y=n))

bar= base + geom_bar(stat = 'identity')

bar

Tabla de Pareto:

pareto.chart(table(datos$MATH),cumperc = c(0,50,80,100))

##       
## Pareto chart analysis for table(datos$MATH)
##          Frequency   Cum.Freq.  Percentage Cum.Percent.
##   55.5  13.0000000  13.0000000   2.1666667    2.1666667
##   48    12.0000000  25.0000000   2.0000000    4.1666667
##   41.9  11.0000000  36.0000000   1.8333333    6.0000000
##   59.6  10.0000000  46.0000000   1.6666667    7.6666667
##   41     8.0000000  54.0000000   1.3333333    9.0000000
##   51.3   8.0000000  62.0000000   1.3333333   10.3333333
##   40.3   7.0000000  69.0000000   1.1666667   11.5000000
##   41.2   7.0000000  76.0000000   1.1666667   12.6666667
##   42.8   7.0000000  83.0000000   1.1666667   13.8333333
##   45.9   7.0000000  90.0000000   1.1666667   15.0000000
##   46.2   7.0000000  97.0000000   1.1666667   16.1666667
##   47.1   7.0000000 104.0000000   1.1666667   17.3333333
##   49.5   7.0000000 111.0000000   1.1666667   18.5000000
##   53     7.0000000 118.0000000   1.1666667   19.6666667
##   54.6   7.0000000 125.0000000   1.1666667   20.8333333
##   56.3   7.0000000 132.0000000   1.1666667   22.0000000
##   38.6   6.0000000 138.0000000   1.0000000   23.0000000
##   40.2   6.0000000 144.0000000   1.0000000   24.0000000
##   44.5   6.0000000 150.0000000   1.0000000   25.0000000
##   50.3   6.0000000 156.0000000   1.0000000   26.0000000
##   50.4   6.0000000 162.0000000   1.0000000   27.0000000
##   51.1   6.0000000 168.0000000   1.0000000   28.0000000
##   52.2   6.0000000 174.0000000   1.0000000   29.0000000
##   52.9   6.0000000 180.0000000   1.0000000   30.0000000
##   55.3   6.0000000 186.0000000   1.0000000   31.0000000
##   57.9   6.0000000 192.0000000   1.0000000   32.0000000
##   37.7   5.0000000 197.0000000   0.8333333   32.8333333
##   38.4   5.0000000 202.0000000   0.8333333   33.6666667
##   46.1   5.0000000 207.0000000   0.8333333   34.5000000
##   53.7   5.0000000 212.0000000   0.8333333   35.3333333
##   53.9   5.0000000 217.0000000   0.8333333   36.1666667
##   58.1   5.0000000 222.0000000   0.8333333   37.0000000
##   58.8   5.0000000 227.0000000   0.8333333   37.8333333
##   60.5   5.0000000 232.0000000   0.8333333   38.6666667
##   61.2   5.0000000 237.0000000   0.8333333   39.5000000
##   61.4   5.0000000 242.0000000   0.8333333   40.3333333
##   62.3   5.0000000 247.0000000   0.8333333   41.1666667
##   63     5.0000000 252.0000000   0.8333333   42.0000000
##   64     5.0000000 257.0000000   0.8333333   42.8333333
##   72.2   5.0000000 262.0000000   0.8333333   43.6666667
##   35.3   4.0000000 266.0000000   0.6666667   44.3333333
##   36.9   4.0000000 270.0000000   0.6666667   45.0000000
##   42.9   4.0000000 274.0000000   0.6666667   45.6666667
##   44.3   4.0000000 278.0000000   0.6666667   46.3333333
##   45.1   4.0000000 282.0000000   0.6666667   47.0000000
##   45.4   4.0000000 286.0000000   0.6666667   47.6666667
##   50.6   4.0000000 290.0000000   0.6666667   48.3333333
##   51.8   4.0000000 294.0000000   0.6666667   49.0000000
##   56.2   4.0000000 298.0000000   0.6666667   49.6666667
##   57     4.0000000 302.0000000   0.6666667   50.3333333
##   57.2   4.0000000 306.0000000   0.6666667   51.0000000
##   62.8   4.0000000 310.0000000   0.6666667   51.6666667
##   64.5   4.0000000 314.0000000   0.6666667   52.3333333
##   65.4   4.0000000 318.0000000   0.6666667   53.0000000
##   67.1   4.0000000 322.0000000   0.6666667   53.6666667
##   70.5   4.0000000 326.0000000   0.6666667   54.3333333
##   71.3   4.0000000 330.0000000   0.6666667   55.0000000
##   33.7   3.0000000 333.0000000   0.5000000   55.5000000
##   38.7   3.0000000 336.0000000   0.5000000   56.0000000
##   39.5   3.0000000 339.0000000   0.5000000   56.5000000
##   42.6   3.0000000 342.0000000   0.5000000   57.0000000
##   43.5   3.0000000 345.0000000   0.5000000   57.5000000
##   43.6   3.0000000 348.0000000   0.5000000   58.0000000
##   43.8   3.0000000 351.0000000   0.5000000   58.5000000
##   45.5   3.0000000 354.0000000   0.5000000   59.0000000
##   46.3   3.0000000 357.0000000   0.5000000   59.5000000
##   46.8   3.0000000 360.0000000   0.5000000   60.0000000
##   46.9   3.0000000 363.0000000   0.5000000   60.5000000
##   47.7   3.0000000 366.0000000   0.5000000   61.0000000
##   47.8   3.0000000 369.0000000   0.5000000   61.5000000
##   48.5   3.0000000 372.0000000   0.5000000   62.0000000
##   48.7   3.0000000 375.0000000   0.5000000   62.5000000
##   48.8   3.0000000 378.0000000   0.5000000   63.0000000
##   49.4   3.0000000 381.0000000   0.5000000   63.5000000
##   51.4   3.0000000 384.0000000   0.5000000   64.0000000
##   51.9   3.0000000 387.0000000   0.5000000   64.5000000
##   52     3.0000000 390.0000000   0.5000000   65.0000000
##   52.4   3.0000000 393.0000000   0.5000000   65.5000000
##   54.4   3.0000000 396.0000000   0.5000000   66.0000000
##   54.8   3.0000000 399.0000000   0.5000000   66.5000000
##   56.8   3.0000000 402.0000000   0.5000000   67.0000000
##   56.9   3.0000000 405.0000000   0.5000000   67.5000000
##   58.9   3.0000000 408.0000000   0.5000000   68.0000000
##   60.4   3.0000000 411.0000000   0.5000000   68.5000000
##   63.8   3.0000000 414.0000000   0.5000000   69.0000000
##   64.7   3.0000000 417.0000000   0.5000000   69.5000000
##   66.3   3.0000000 420.0000000   0.5000000   70.0000000
##   66.4   3.0000000 423.0000000   0.5000000   70.5000000
##   67     3.0000000 426.0000000   0.5000000   71.0000000
##   68     3.0000000 429.0000000   0.5000000   71.5000000
##   69.6   3.0000000 432.0000000   0.5000000   72.0000000
##   74.6   3.0000000 435.0000000   0.5000000   72.5000000
##   35.1   2.0000000 437.0000000   0.3333333   72.8333333
##   36     2.0000000 439.0000000   0.3333333   73.1666667
##   36.1   2.0000000 441.0000000   0.3333333   73.5000000
##   37.6   2.0000000 443.0000000   0.3333333   73.8333333
##   40.4   2.0000000 445.0000000   0.3333333   74.1666667
##   40.9   2.0000000 447.0000000   0.3333333   74.5000000
##   41.4   2.0000000 449.0000000   0.3333333   74.8333333
##   41.7   2.0000000 451.0000000   0.3333333   75.1666667
##   42.1   2.0000000 453.0000000   0.3333333   75.5000000
##   42.2   2.0000000 455.0000000   0.3333333   75.8333333
##   43.1   2.0000000 457.0000000   0.3333333   76.1666667
##   44.2   2.0000000 459.0000000   0.3333333   76.5000000
##   44.7   2.0000000 461.0000000   0.3333333   76.8333333
##   44.8   2.0000000 463.0000000   0.3333333   77.1666667
##   45.2   2.0000000 465.0000000   0.3333333   77.5000000
##   45.6   2.0000000 467.0000000   0.3333333   77.8333333
##   45.7   2.0000000 469.0000000   0.3333333   78.1666667
##   48.1   2.0000000 471.0000000   0.3333333   78.5000000
##   49.2   2.0000000 473.0000000   0.3333333   78.8333333
##   49.9   2.0000000 475.0000000   0.3333333   79.1666667
##   50.5   2.0000000 477.0000000   0.3333333   79.5000000
##   51.6   2.0000000 479.0000000   0.3333333   79.8333333
##   53.1   2.0000000 481.0000000   0.3333333   80.1666667
##   53.6   2.0000000 483.0000000   0.3333333   80.5000000
##   54.3   2.0000000 485.0000000   0.3333333   80.8333333
##   55.7   2.0000000 487.0000000   0.3333333   81.1666667
##   56.4   2.0000000 489.0000000   0.3333333   81.5000000
##   56.5   2.0000000 491.0000000   0.3333333   81.8333333
##   56.6   2.0000000 493.0000000   0.3333333   82.1666667
##   57.4   2.0000000 495.0000000   0.3333333   82.5000000
##   59.8   2.0000000 497.0000000   0.3333333   82.8333333
##   61.9   2.0000000 499.0000000   0.3333333   83.1666667
##   62.1   2.0000000 501.0000000   0.3333333   83.5000000
##   63.1   2.0000000 503.0000000   0.3333333   83.8333333
##   63.7   2.0000000 505.0000000   0.3333333   84.1666667
##   64.1   2.0000000 507.0000000   0.3333333   84.5000000
##   66.1   2.0000000 509.0000000   0.3333333   84.8333333
##   67.9   2.0000000 511.0000000   0.3333333   85.1666667
##   68.9   2.0000000 513.0000000   0.3333333   85.5000000
##   75.5   2.0000000 515.0000000   0.3333333   85.8333333
##   31.8   1.0000000 516.0000000   0.1666667   86.0000000
##   32.7   1.0000000 517.0000000   0.1666667   86.1666667
##   33.4   1.0000000 518.0000000   0.1666667   86.3333333
##   34.4   1.0000000 519.0000000   0.1666667   86.5000000
##   36.4   1.0000000 520.0000000   0.1666667   86.6666667
##   36.7   1.0000000 521.0000000   0.1666667   86.8333333
##   37.2   1.0000000 522.0000000   0.1666667   87.0000000
##   37.9   1.0000000 523.0000000   0.1666667   87.1666667
##   38.3   1.0000000 524.0000000   0.1666667   87.3333333
##   38.5   1.0000000 525.0000000   0.1666667   87.5000000
##   38.8   1.0000000 526.0000000   0.1666667   87.6666667
##   39.3   1.0000000 527.0000000   0.1666667   87.8333333
##   39.9   1.0000000 528.0000000   0.1666667   88.0000000
##   40.5   1.0000000 529.0000000   0.1666667   88.1666667
##   40.6   1.0000000 530.0000000   0.1666667   88.3333333
##   40.7   1.0000000 531.0000000   0.1666667   88.5000000
##   41.5   1.0000000 532.0000000   0.1666667   88.6666667
##   41.8   1.0000000 533.0000000   0.1666667   88.8333333
##   42     1.0000000 534.0000000   0.1666667   89.0000000
##   42.3   1.0000000 535.0000000   0.1666667   89.1666667
##   42.4   1.0000000 536.0000000   0.1666667   89.3333333
##   42.5   1.0000000 537.0000000   0.1666667   89.5000000
##   43     1.0000000 538.0000000   0.1666667   89.6666667
##   43.2   1.0000000 539.0000000   0.1666667   89.8333333
##   44.4   1.0000000 540.0000000   0.1666667   90.0000000
##   44.6   1.0000000 541.0000000   0.1666667   90.1666667
##   45     1.0000000 542.0000000   0.1666667   90.3333333
##   45.3   1.0000000 543.0000000   0.1666667   90.5000000
##   46.4   1.0000000 544.0000000   0.1666667   90.6666667
##   46.5   1.0000000 545.0000000   0.1666667   90.8333333
##   47.4   1.0000000 546.0000000   0.1666667   91.0000000
##   47.5   1.0000000 547.0000000   0.1666667   91.1666667
##   48.2   1.0000000 548.0000000   0.1666667   91.3333333
##   48.3   1.0000000 549.0000000   0.1666667   91.5000000
##   48.6   1.0000000 550.0000000   0.1666667   91.6666667
##   49     1.0000000 551.0000000   0.1666667   91.8333333
##   49.1   1.0000000 552.0000000   0.1666667   92.0000000
##   49.3   1.0000000 553.0000000   0.1666667   92.1666667
##   50.1   1.0000000 554.0000000   0.1666667   92.3333333
##   50.9   1.0000000 555.0000000   0.1666667   92.5000000
##   51     1.0000000 556.0000000   0.1666667   92.6666667
##   51.2   1.0000000 557.0000000   0.1666667   92.8333333
##   51.5   1.0000000 558.0000000   0.1666667   93.0000000
##   51.7   1.0000000 559.0000000   0.1666667   93.1666667
##   52.1   1.0000000 560.0000000   0.1666667   93.3333333
##   52.3   1.0000000 561.0000000   0.1666667   93.5000000
##   52.7   1.0000000 562.0000000   0.1666667   93.6666667
##   53.2   1.0000000 563.0000000   0.1666667   93.8333333
##   53.4   1.0000000 564.0000000   0.1666667   94.0000000
##   54.7   1.0000000 565.0000000   0.1666667   94.1666667
##   54.9   1.0000000 566.0000000   0.1666667   94.3333333
##   55.2   1.0000000 567.0000000   0.1666667   94.5000000
##   55.8   1.0000000 568.0000000   0.1666667   94.6666667
##   56.1   1.0000000 569.0000000   0.1666667   94.8333333
##   57.3   1.0000000 570.0000000   0.1666667   95.0000000
##   57.8   1.0000000 571.0000000   0.1666667   95.1666667
##   58     1.0000000 572.0000000   0.1666667   95.3333333
##   58.2   1.0000000 573.0000000   0.1666667   95.5000000
##   58.3   1.0000000 574.0000000   0.1666667   95.6666667
##   58.6   1.0000000 575.0000000   0.1666667   95.8333333
##   58.7   1.0000000 576.0000000   0.1666667   96.0000000
##   59.3   1.0000000 577.0000000   0.1666667   96.1666667
##   59.7   1.0000000 578.0000000   0.1666667   96.3333333
##   60     1.0000000 579.0000000   0.1666667   96.5000000
##   60.2   1.0000000 580.0000000   0.1666667   96.6666667
##   60.6   1.0000000 581.0000000   0.1666667   96.8333333
##   61.1   1.0000000 582.0000000   0.1666667   97.0000000
##   61.3   1.0000000 583.0000000   0.1666667   97.1666667
##   61.5   1.0000000 584.0000000   0.1666667   97.3333333
##   61.8   1.0000000 585.0000000   0.1666667   97.5000000
##   62     1.0000000 586.0000000   0.1666667   97.6666667
##   62.2   1.0000000 587.0000000   0.1666667   97.8333333
##   62.5   1.0000000 588.0000000   0.1666667   98.0000000
##   63.6   1.0000000 589.0000000   0.1666667   98.1666667
##   64.3   1.0000000 590.0000000   0.1666667   98.3333333
##   65.5   1.0000000 591.0000000   0.1666667   98.5000000
##   65.6   1.0000000 592.0000000   0.1666667   98.6666667
##   68.1   1.0000000 593.0000000   0.1666667   98.8333333
##   68.6   1.0000000 594.0000000   0.1666667   99.0000000
##   68.7   1.0000000 595.0000000   0.1666667   99.1666667
##   69.7   1.0000000 596.0000000   0.1666667   99.3333333
##   70.3   1.0000000 597.0000000   0.1666667   99.5000000
##   70.6   1.0000000 598.0000000   0.1666667   99.6666667
##   72.9   1.0000000 599.0000000   0.1666667   99.8333333
##   73.1   1.0000000 600.0000000   0.1666667  100.0000000

DATOS ESTADÍSTICOS:

MODA

library(DescTools)
Mode(datos$MATH)
## [1] 55.5

CONCENTRACIÓN

dataTable=table(datos$MATH)

# * < 0.01 : indica que la moda no es significativa, las categorias tienen pesos similares.
# * < 0.15 : indica que la moda no es significativa, varias categorias tienen pesos similares.
# * entre 0.15 - 0.3: hay una moda.
# * > 0.3: La moda se diferencia de los demas

Herfindahl(dataTable)
## [1] 0.007483333

REPRESENTATIVIDAD EFECTIVA: LAAKSO - TAAGEPERA

1/sum(prop.table(dataTable)**2)
## [1] 133.6303

Hay casi 144 grupos representativos

MEDIANA: valor de la variable que se encuentra en el centro dentro de un conjunto de datos ordenados, si el número de datos es par, la mediana es la media entre los dos datos centrales.

Median(datos$MATH)
## [1] 51.3
ggplot(datos,aes(y=MATH)) + geom_boxplot() + scale_y_discrete(limits=OrdDf$variable) 

CLASE 3: TABLAS DESDE LA WEB

Cómo descargar data de una tabla que está en la web.

LINKGUERRAS = "https://en.wikipedia.org/wiki/List_of_wars_by_death_toll" 

PREMODERN:

library(htmltab)
ancient = htmltab(doc = LINKGUERRAS, 
               which ='//*[@id="mw-content-text"]/div/table[4]')


medieval = htmltab(doc = LINKGUERRAS, 
               which ='//*[@id="mw-content-text"]/div/table[6]') 
## Warning: Columns [Notes] seem to have no data and are removed. Use
## rm_nodata_cols = F to suppress this behavior

MODERN:

modern = htmltab(doc = LINKGUERRAS, 
               which ='//*[@id="mw-content-text"]/div/table[7]')
## Warning: Columns [Notes] seem to have no data and are removed. Use
## rm_nodata_cols = F to suppress this behavior

Identificando nombre de variables(columnas)

names(ancient)
## [1] "War"                   "Deathrange"            "Geometricmean(Note 1)"
## [4] "Date"                  "Combatants"            "Location"             
## [7] "Notes"
names(medieval)
## [1] "War"           "Deathrange"    "Geometricmean" "Date"         
## [5] "Combatants"    "Location"
names(modern)
## [1] "War"           "Deathrange"    "Geometricmean" "Date"         
## [5] "Comabatants"   "Location"

Si quiero combinar las tres tablas en uno, estas deben tener los mismos nombres

guerras1=ancient[,c("War","Location","Deathrange")]
guerras2=medieval[,c("War","Location","Deathrange")]
guerras3=modern[,c("War","Location","Deathrange")]

Cada data frama tiene tres columnas, ahora uso la siguiente función rbind para juntar la 1, 2 y 3.

guerras=rbind(guerras1,guerras2,guerras3)

USO LA FUNCIÓN STR CUANDO QUIERO JUNTAR ESTOS DATOS EN EL SIGUIENTE FORMANDO, UNO DEBAJO DEL OTRO.

str(guerras)
## 'data.frame':    162 obs. of  3 variables:
##  $ War       : chr  "Conquests of Cyrus the Great" "Greco–Persian Wars" "Samnite Wars" "Wars of Alexander the Great" ...
##  $ Location  : chr  "Middle East" "Greece" "Italy" "Middle East / North Africa / Central Asia / India" ...
##  $ Deathrange: chr  "100,000+" "73,800+" "33,500+" "142,000+" ...

TABLA Ahora yo quiero analizar Location: USO LA FUNCIÓN PARA TABLAS

table(guerras$Location)
## 
##                                       Afghanistan 
##                                                 3 
##                                           Algeria 
##                                                 3 
##                                          Americas 
##                                                 1 
##                                            Angola 
##                                                 2 
##                                  Balkan Peninsula 
##                                                 1 
##                                        Bangladesh 
##                                                 1 
##                                            Bosnia 
##                                                 1 
##                                     British Isles 
##                                                 1 
##                                           Burundi 
##                                                 1 
##                                   Caucasus region 
##                                                 1 
##                                    Central Africa 
##                                                 2 
##                                             China 
##                                                 9 
##                                  China /  Vietnam 
##                                                 1 
##                                          Colombia 
##                                                 3 
##                                             Congo 
##                                                 4 
##                                 Crimean Peninsula 
##                                                 1 
##                                              Cuba 
##                                                 2 
##                                         East Asia 
##                                                 1 
##                                    Eastern Europe 
##                                                 4 
##       Eastern Europe / Middle East / North Africa 
##                                                 1 
##                                           England 
##                                                 2 
##                                   England / Wales 
##                                                 1 
##                                          Ethiopia 
##                                                 2 
##                                           Eurasia 
##                                                 2 
##                                            Europe 
##                                                 4 
##                                 Europe / Americas 
##                                                 2 
##                Europe / Middle East ("Holy Land") 
##                                                 1 
##                                           Finland 
##                                                 1 
##                                            France 
##                                                 3 
##                                           Germany 
##                                                 1 
##                                            Greece 
##                                                 2 
##                                             Haiti 
##                                                 1 
##                                 Iberian Peninsula 
##                                                 1 
##                                             India 
##                                                 4 
##                                  India-Bangladesh 
##                                                 1 
##                                         Indonesia 
##                                                 1 
##                                              Iraq 
##                                                 5 
##                                             Italy 
##                                                 1 
##                                             Korea 
##                                                 3 
##                                              Laos 
##                                                 1 
##                                           Lebanon 
##                                                 1 
##                                             Libya 
##                                                 1 
##                                        Madagascar 
##                                                 1 
##                                         Manchuria 
##                                                 1 
##                                            Mexico 
##                                                 4 
##                                       Middle East 
##                                                 7 
##                        Middle East / North Africa 
##                                                 1 
## Middle East / North Africa / Central Asia / India 
##                                                 1 
##      Middle East / North Africa / Southern Europe 
##                                                 1 
##                          Middle East/North Africa 
##                                                 1 
##                                        Mozambique 
##                                                 1 
##                                           Myanmar 
##                                                 1 
##                                        New Guinea 
##                                                 1 
##                                           Nigeria 
##                                                 2 
##                                      North Africa 
##                                                 1 
##                                     North America 
##                                                 1 
##                            North India / Pakistan 
##                                                 1 
##                                   Northeast India 
##                                                 2 
##                                    Northern China 
##                                                 1 
##                                   Northern Europe 
##                                                 1 
##                                          Pakistan 
##                                                 1 
##                                         Patagonia 
##                                                 1 
##                                              Peru 
##                                                 2 
##                                       Philippines 
##                                                 3 
##                                            Russia 
##                                                 2 
##                                            Rwanda 
##                                                 1 
##                                Scotland / England 
##                                                 1 
##                                      Sierra Leone 
##                                                 1 
##                                           Somalia 
##                                                 1 
##                                      South Africa 
##                                                 1 
##                                     South America 
##                                                 1 
##                                    Southeast Asia 
##                                                 2 
##                                  Southeast Europe 
##                                                 1 
##                                   Southern Africa 
##                                                 1 
##                                   Southern Europe 
##                                                 1 
##                    Southern Europe / North Africa 
##                                                 2 
##                                             Spain 
##                                                 2 
##                                         Sri Lanka 
##                                                 1 
##                                             Sudan 
##                                                 3 
##                                             Syria 
##                                                 1 
##                                           Tunisia 
##                                                 1 
##                                            Uganda 
##                                                 1 
##                                               USA 
##                                                 1 
##                                         Venezuela 
##                                                 1 
##                                           Vietnam 
##                                                 1 
##                                    Western Europe 
##                                                 4 
##                     Western Europe / North Africa 
##                                                 2 
##                                         Worldwide 
##                                                 7 
##                                             Yemen 
##                                                 2

Pero para hacer que esa tabla de datos se vea mejor y más ordenada uso el otro cógio para crear tablas, el código lo consigo agregando “datatable=”. Pero además usaré otro elementos

library(knitr)
datatable=(table(guerras$Location))
kable(datatable)
Var1 Freq
Afghanistan 3
Algeria 3
Americas 1
Angola 2
Balkan Peninsula 1
Bangladesh 1
Bosnia 1
British Isles 1
Burundi 1
Caucasus region 1
Central Africa 2
China 9
China / Vietnam 1
Colombia 3
Congo 4
Crimean Peninsula 1
Cuba 2
East Asia 1
Eastern Europe 4
Eastern Europe / Middle East / North Africa 1
England 2
England / Wales 1
Ethiopia 2
Eurasia 2
Europe 4
Europe / Americas 2
Europe / Middle East (“Holy Land”) 1
Finland 1
France 3
Germany 1
Greece 2
Haiti 1
Iberian Peninsula 1
India 4
India-Bangladesh 1
Indonesia 1
Iraq 5
Italy 1
Korea 3
Laos 1
Lebanon 1
Libya 1
Madagascar 1
Manchuria 1
Mexico 4
Middle East 7
Middle East / North Africa 1
Middle East / North Africa / Central Asia / India 1
Middle East / North Africa / Southern Europe 1
Middle East/North Africa 1
Mozambique 1
Myanmar 1
New Guinea 1
Nigeria 2
North Africa 1
North America 1
North India / Pakistan 1
Northeast India 2
Northern China 1
Northern Europe 1
Pakistan 1
Patagonia 1
Peru 2
Philippines 3
Russia 2
Rwanda 1
Scotland / England 1
Sierra Leone 1
Somalia 1
South Africa 1
South America 1
Southeast Asia 2
Southeast Europe 1
Southern Africa 1
Southern Europe 1
Southern Europe / North Africa 2
Spain 2
Sri Lanka 1
Sudan 3
Syria 1
Tunisia 1
Uganda 1
USA 1
Venezuela 1
Vietnam 1
Western Europe 4
Western Europe / North Africa 2
Worldwide 7
Yemen 2

GRÁFICOS Versión básica, sin títulos

library(ggplot2)
base = ggplot(data=guerras,aes(x=Location))
bar1 = base + geom_bar()
bar1 

Con títulos

bar1 = bar1 + labs(x="Pais/zona", 
                   y="Cantidad",
                  title="Locación de las Guerras en la historia", 
                  subtitle = "Solo con mas 25000 muertos",
                  caption = "Fuente: Wikipedia") 

bar1

Ajustando las medidas

bar1 + theme(axis.text.x = element_text(angle = 90,size=7,hjust = 1))

Datos estadísticos

MODA:

library(DescTools)
Mode(guerras$Location)
## [1] "China"

< 0.01 : indica que la moda no es significativa, las categorias tienen pesos similares. < 0.15 : indica que la moda no es significativa, varias categorias tienen pesos similares. entre 0.15 - 0.25: hay una moda. 0.25: La moda se diferencia de los demas

HERFINDAHL

Herfindahl(datatable)
## [1] 0.01851852

REPRESENTATIVIDAD

1/Herfindahl(datatable)
## [1] 54