5 Recursos
R pre-introductorio discute una serie de recursos para conocer y perfeccionar R.
5.1 Base R
En lo fundamental, programar en R es aplicar funciones a objetos. Ya hemos analizado que, por ejemplo, un data frame es un objeto y sobre ese objeto se pueden ejecutar ciertas funciones y no otras. Si esto aún no está completamente interiorizado, es mejor releer el capítulo anterior.
Las funciones están contenidas en paquetes que uno mismo debe instalar y cargar (instalar y cargar, ambas acciones son necesarias y corresponden, respectivamente, a las funciones install.packages()
y library()
):
## Install package
install.packages("skimr")
## Load package
library(skimr)
Una de las características fenomenales de R radica en la posibilidad de instalar paquetes que disparan su versatilidad y poder de análisis. El catálogo de paquetes adicionales es impresionante. R, no obstante, ya trae consigo artillería pesada: un conjunto de paquetes (como base, stats, utils) instalados de origen y que son suficientes para habilitar un sinnúmero de acciones.
Al conjunto de paquetes que no hace falta instalar porque R ya los trae se le conoce como Base R. Dado que Base R también contiene la mayoría de la sintaxis que regularmente empleamos al escribir código, perfeccionar su uso es una obligación si queremos destacar como programadores.
Un temario de fundamentos para cualquier persona novata en programación se parecería al siguiente:
- Tipos y estructuras de objetos.
- Funciones.
- Indexación y selección.
-
Missing values (
NA
). - Operadores lógicos.
- Estructuras de control.
- Iteraciones.
- Pipes.
- Regular expressions.
Un excelente material -¡y es gratis!- para cubrir la mayor parte de ese catálogo es Hands-On Programming with R. Mi fe en este libro es de tal magnitud que apenas terminar R pre-introductorio yo empezaría por ahí. R Programming for Data Science no pinta mal como recurso auxiliar. En español, tal vez los primeros capítulos del ebook de Rafael A. Irizarry hagan el trabajo.
5.2 Tidyverse
Mencioné en el punto anterior que R cuenta con su propio conjunto de paquetes: Base R. Los paquetes de Base R ya vienen instalados y no hace falta ni cargarlos.
Hay quienes hacen de Base R su estilo de programación; estas personas optan por escribir código que, en la medida de lo realizable, recurre únicamente a la paquetería nativa de R. En la otra esquina están generalmente quienes instalan la paquetería Tidyverse, punta de lanza de una segunda y muy influyente escuela de programación.
Tidyverse ofrece una gama de paquetes para curar, transformar, modelar, visualizar y comunicar datos, con funciones generalmente más eficientes y de sintaxis más clara y estética que la que caracteriza a las funciones de Base R.
Yo, personalmente, soy un enamorado de Tidyverse y recomiendo muchísimo adquirir habilidades en los siguientes tres paquetes:
- readr, especializado en carga de datos.
- dplyr, especializado en transformación de datos.
- ggplot2, especializado en visualización de datos.
Tidyverse incluye otros paquetes espectacularmente útiles, pero esos tres son los esenciales para principiantes. A efectos de combinar el abordaje del temario del punto anterior con la paquetería Tidyverse, no podría recomendar más categóricamente el excelente curso virtual Statistical Programming in R de Kelsey Gonzalez, una profesional joven que encarna a la perfección el concepto de Computational Social Scientist.
El mejor material -¡y también es gratis!- para obsesionarse con Tidyverse es R for Data Science, escrito por el autor de varios de estos paquetes, Hadley Wickham, quien además firma este otro libro de carácter avanzado -muy esclarecedor para conocer mejor los entresijos de R- y este artículo fundacional que ahora mismo carece de urgencia pero que uno debe leer sí o sí si la misión de incursionar en este campo va en serio.
R for Data Science de Hadley Wickham es un libro de programación orientada a Data Science, mientras R pre-introductorio es un libro de programación orientado a que ustedes puedan asimilar más fácilmente los contenidos de R for Data Science.
En conclusión, el plan de estudio que yo aconsejo para aprender a programar en R consiste en completar R pre-introductorio y seguidamente trabajar a la vez con Hands-On Programming with R y R for Data Science (tiene una versión en español), alternando entre ambos un poco pero priorizando R for Data Science apenas vayan sintiendo más confianza. Lo mejor de estos dos libros es que son súper pedagógicos, sostenerles el ritmo no cuesta nada.
Si alguien me dijese que esto de los libros no se le da pero que sí goza de buena comprensión del inglés, entonces le recomendaría entregarse con total confianza al notable curso de Kelsey Gonzalez que mencioné antes.
5.3 Choose your fighter!
Aquí vamos a ver cómo cada estilo lleva a cabo una misma tarea. Pilas con esta sección porque de paso regala un montón de código útil y de uso frecuente.
Vamos a trabajar con el conjunto de datos mammals
del paquete MASS
, que voy a acomodar mínimamente antes de usarlo:
## Prepare data
mammals <- MASS::mammals
mammals$mammal <- row.names(mammals)
row.names(mammals) <- NULL
df <- mammals
## Explore data
head(df)
#> body brain mammal
#> 1 3.385 44.5 Arctic fox
#> 2 0.480 15.5 Owl monkey
#> 3 1.350 8.1 Mountain beaver
#> 4 465.000 423.0 Cow
#> 5 36.330 119.5 Grey wolf
#> 6 27.660 115.0 Goat
Así empieza lo bueno:
5.3.1 Filtrar observaciones
## Filter (Base R)
df[which(df$mammal == "Cow" | df$mammal == "Human"), ]
#> body brain mammal
#> 4 465 423 Cow
#> 32 62 1320 Human
## Filter (Tidyverse)
df |>
filter(mammal == "Cow" | mammal == "Human")
#> body brain mammal
#> 1 465 423 Cow
#> 2 62 1320 Human
5.3.2 Seleccionar variables
## Select (Base R)
df[c("mammal", "body")] |> car::some()
#> mammal body
#> 3 Mountain beaver 1.350
#> 5 Grey wolf 36.330
#> 17 Tree hyrax 2.000
#> 21 Donkey 187.100
#> 24 Patas monkey 10.000
#> 33 African elephant 6654.000
#> 46 Chimpanzee 52.160
#> 51 Raccoon 4.288
#> 57 Echidna 3.000
#> 61 Tree shrew 0.104
## Select (Tidyverse)
df |>
select(mammal, body) # Conflict with MASS::select
#> Error in select(df, mammal, body): unused arguments (mammal, body)
Este código no funcionó por un conflicto de funciones: los paquetes dplyr
y MASS
, ambos instalados en este momento, tienen una función select
; yo escribí el código pensando en la función dplyr::select()
, pero R optó por usar MASS::select()
, posiblemente porque es la del paquete de más reciente instalación.
Los conflictos de funciones son más o menos difíciles de detectar cuando uno está forjando sus primeras armas en R. Hay dos formas de resolverlos. La primera es siendo explícitso respecto a la función de cuál paquete usar:
## Select (Tidyverse)
df |>
dplyr::select(mammal, body) |> car::some()
#> mammal body
#> 2 Owl monkey 0.48
#> 7 Roe deer 14.83
#> 17 Tree hyrax 2.00
#> 18 N.A. opossum 1.70
#> 24 Patas monkey 10.00
#> 38 Golden hamster 0.12
#> 40 Little brown bat 0.01
#> 41 Slow loris 1.40
#> 56 Pig 192.00
#> 58 Brazilian tapir 160.00
En adelante tendría que repetir eso mismo cada vez que quiera usar select()
. Una alternativa para zanjar el conflicto de funciones de una vez y para siempre lo brinda la función conflict_prefer()
del paquete conflicted
:
## Settle conflict
conflict_prefer(name = "select", winner = "dplyr")
#> [conflicted] Removing existing preference
#> [conflicted] Will prefer dplyr::select over any other package
## Select (Tidyverse)
df |>
select(mammal, body) |> car::some()
#> mammal body
#> 1 Arctic fox 3.385
#> 8 Guinea pig 1.040
#> 12 Arctic ground squirrel 0.920
#> 15 Star-nosed mole 0.060
#> 25 Cat 3.300
#> 48 Desert hedgehog 0.550
#> 49 Giant armadillo 60.000
#> 51 Raccoon 4.288
#> 61 Tree shrew 0.104
#> 62 Red fox 4.235
Por cierto, |> car::some()
es sintaxis que incluyo para que R me devuelva nada más una muestra del data frame.
5.3.3 Filtrar y seleccionar variables (al mismo tiempo)
## Subset (Base R)
df1 <- subset(df,
body > 6,
select = c(mammal, body))
## Order (Base R)
df1[order(df1$body), ]
#> mammal body
#> 35 Rhesus monkey 6.80
#> 24 Patas monkey 10.00
#> 47 Baboon 10.55
#> 7 Roe deer 14.83
#> 6 Goat 27.66
#> 36 Kangaroo 35.00
#> 5 Grey wolf 36.33
#> 46 Chimpanzee 52.16
#> 44 Sheep 55.50
#> 49 Giant armadillo 60.00
#> 32 Human 62.00
#> 30 Grey seal 85.00
#> 45 Jaguar 100.00
#> 58 Brazilian tapir 160.00
#> 21 Donkey 187.10
#> 56 Pig 192.00
#> 29 Gorilla 207.00
#> 42 Okapi 250.00
#> 4 Cow 465.00
#> 22 Horse 521.00
#> 28 Giraffe 529.00
#> 19 Asian elephant 2547.00
#> 33 African elephant 6654.00
## Filter, select, and arrange (Tidyverse)
df |>
filter(body > 6) |>
select(mammal, body) |>
arrange(body)
#> mammal body
#> 1 Rhesus monkey 6.80
#> 2 Patas monkey 10.00
#> 3 Baboon 10.55
#> 4 Roe deer 14.83
#> 5 Goat 27.66
#> 6 Kangaroo 35.00
#> 7 Grey wolf 36.33
#> 8 Chimpanzee 52.16
#> 9 Sheep 55.50
#> 10 Giant armadillo 60.00
#> 11 Human 62.00
#> 12 Grey seal 85.00
#> 13 Jaguar 100.00
#> 14 Brazilian tapir 160.00
#> 15 Donkey 187.10
#> 16 Pig 192.00
#> 17 Gorilla 207.00
#> 18 Okapi 250.00
#> 19 Cow 465.00
#> 20 Horse 521.00
#> 21 Giraffe 529.00
#> 22 Asian elephant 2547.00
#> 23 African elephant 6654.00
5.3.4 Renombrar variables
## Rename (Tidyverse)
df |>
rename(mammal = MAMMALS) |>
head()
#> body brain mammal
#> 1 3.385 44.5 Arctic fox
#> 2 0.480 15.5 Owl monkey
#> 3 1.350 8.1 Mountain beaver
#> 4 465.000 423.0 Cow
#> 5 36.330 119.5 Grey wolf
#> 6 27.660 115.0 Goat
## Inspect (big fail!)
names(df)
#> [1] "body" "brain" "MAMMALS"
## Rename it again and save the result
df <- df |>
rename(mammal = MAMMALS)
## Inspect (job done!)
names(df)
#> [1] "body" "brain" "mammal"
5.3.5 Extraer variables
## Pull (Base R)
df[[3]]
#> [1] "Arctic fox" "Owl monkey"
#> [3] "Mountain beaver" "Cow"
#> [5] "Grey wolf" "Goat"
#> [7] "Roe deer" "Guinea pig"
#> [9] "Verbet" "Chinchilla"
#> [11] "Ground squirrel" "Arctic ground squirrel"
#> [13] "African giant pouched rat" "Lesser short-tailed shrew"
#> [15] "Star-nosed mole" "Nine-banded armadillo"
#> [17] "Tree hyrax" "N.A. opossum"
#> [19] "Asian elephant" "Big brown bat"
#> [21] "Donkey" "Horse"
#> [23] "European hedgehog" "Patas monkey"
#> [25] "Cat" "Galago"
#> [27] "Genet" "Giraffe"
#> [29] "Gorilla" "Grey seal"
#> [31] "Rock hyrax-a" "Human"
#> [33] "African elephant" "Water opossum"
#> [35] "Rhesus monkey" "Kangaroo"
#> [37] "Yellow-bellied marmot" "Golden hamster"
#> [39] "Mouse" "Little brown bat"
#> [41] "Slow loris" "Okapi"
#> [43] "Rabbit" "Sheep"
#> [45] "Jaguar" "Chimpanzee"
#> [47] "Baboon" "Desert hedgehog"
#> [49] "Giant armadillo" "Rock hyrax-b"
#> [51] "Raccoon" "Rat"
#> [53] "E. American mole" "Mole rat"
#> [55] "Musk shrew" "Pig"
#> [57] "Echidna" "Brazilian tapir"
#> [59] "Tenrec" "Phalanger"
#> [61] "Tree shrew" "Red fox"
## Pull (Base R)
df$mammal
#> [1] "Arctic fox" "Owl monkey"
#> [3] "Mountain beaver" "Cow"
#> [5] "Grey wolf" "Goat"
#> [7] "Roe deer" "Guinea pig"
#> [9] "Verbet" "Chinchilla"
#> [11] "Ground squirrel" "Arctic ground squirrel"
#> [13] "African giant pouched rat" "Lesser short-tailed shrew"
#> [15] "Star-nosed mole" "Nine-banded armadillo"
#> [17] "Tree hyrax" "N.A. opossum"
#> [19] "Asian elephant" "Big brown bat"
#> [21] "Donkey" "Horse"
#> [23] "European hedgehog" "Patas monkey"
#> [25] "Cat" "Galago"
#> [27] "Genet" "Giraffe"
#> [29] "Gorilla" "Grey seal"
#> [31] "Rock hyrax-a" "Human"
#> [33] "African elephant" "Water opossum"
#> [35] "Rhesus monkey" "Kangaroo"
#> [37] "Yellow-bellied marmot" "Golden hamster"
#> [39] "Mouse" "Little brown bat"
#> [41] "Slow loris" "Okapi"
#> [43] "Rabbit" "Sheep"
#> [45] "Jaguar" "Chimpanzee"
#> [47] "Baboon" "Desert hedgehog"
#> [49] "Giant armadillo" "Rock hyrax-b"
#> [51] "Raccoon" "Rat"
#> [53] "E. American mole" "Mole rat"
#> [55] "Musk shrew" "Pig"
#> [57] "Echidna" "Brazilian tapir"
#> [59] "Tenrec" "Phalanger"
#> [61] "Tree shrew" "Red fox"
## Pull (Tidyverse)
pull(df, 3)
#> [1] "Arctic fox" "Owl monkey"
#> [3] "Mountain beaver" "Cow"
#> [5] "Grey wolf" "Goat"
#> [7] "Roe deer" "Guinea pig"
#> [9] "Verbet" "Chinchilla"
#> [11] "Ground squirrel" "Arctic ground squirrel"
#> [13] "African giant pouched rat" "Lesser short-tailed shrew"
#> [15] "Star-nosed mole" "Nine-banded armadillo"
#> [17] "Tree hyrax" "N.A. opossum"
#> [19] "Asian elephant" "Big brown bat"
#> [21] "Donkey" "Horse"
#> [23] "European hedgehog" "Patas monkey"
#> [25] "Cat" "Galago"
#> [27] "Genet" "Giraffe"
#> [29] "Gorilla" "Grey seal"
#> [31] "Rock hyrax-a" "Human"
#> [33] "African elephant" "Water opossum"
#> [35] "Rhesus monkey" "Kangaroo"
#> [37] "Yellow-bellied marmot" "Golden hamster"
#> [39] "Mouse" "Little brown bat"
#> [41] "Slow loris" "Okapi"
#> [43] "Rabbit" "Sheep"
#> [45] "Jaguar" "Chimpanzee"
#> [47] "Baboon" "Desert hedgehog"
#> [49] "Giant armadillo" "Rock hyrax-b"
#> [51] "Raccoon" "Rat"
#> [53] "E. American mole" "Mole rat"
#> [55] "Musk shrew" "Pig"
#> [57] "Echidna" "Brazilian tapir"
#> [59] "Tenrec" "Phalanger"
#> [61] "Tree shrew" "Red fox"
## Pull (Tidyverse)
pull(df, mammal)
#> [1] "Arctic fox" "Owl monkey"
#> [3] "Mountain beaver" "Cow"
#> [5] "Grey wolf" "Goat"
#> [7] "Roe deer" "Guinea pig"
#> [9] "Verbet" "Chinchilla"
#> [11] "Ground squirrel" "Arctic ground squirrel"
#> [13] "African giant pouched rat" "Lesser short-tailed shrew"
#> [15] "Star-nosed mole" "Nine-banded armadillo"
#> [17] "Tree hyrax" "N.A. opossum"
#> [19] "Asian elephant" "Big brown bat"
#> [21] "Donkey" "Horse"
#> [23] "European hedgehog" "Patas monkey"
#> [25] "Cat" "Galago"
#> [27] "Genet" "Giraffe"
#> [29] "Gorilla" "Grey seal"
#> [31] "Rock hyrax-a" "Human"
#> [33] "African elephant" "Water opossum"
#> [35] "Rhesus monkey" "Kangaroo"
#> [37] "Yellow-bellied marmot" "Golden hamster"
#> [39] "Mouse" "Little brown bat"
#> [41] "Slow loris" "Okapi"
#> [43] "Rabbit" "Sheep"
#> [45] "Jaguar" "Chimpanzee"
#> [47] "Baboon" "Desert hedgehog"
#> [49] "Giant armadillo" "Rock hyrax-b"
#> [51] "Raccoon" "Rat"
#> [53] "E. American mole" "Mole rat"
#> [55] "Musk shrew" "Pig"
#> [57] "Echidna" "Brazilian tapir"
#> [59] "Tenrec" "Phalanger"
#> [61] "Tree shrew" "Red fox"
5.3.6 Recodificar valores
## Prepare data
df2 <- df[, c(1, 3)]
## Recode (Base R)
df2$mammal.cat[df2$body > 50] <- "big_mammal"
df2$mammal.cat[df2$body <= 50] <- "not_that_big"
## Inspect
head(df2, 20)
#> body mammal mammal.cat
#> 1 3.385 Arctic fox not_that_big
#> 2 0.480 Owl monkey not_that_big
#> 3 1.350 Mountain beaver not_that_big
#> 4 465.000 Cow big_mammal
#> 5 36.330 Grey wolf not_that_big
#> 6 27.660 Goat not_that_big
#> 7 14.830 Roe deer not_that_big
#> 8 1.040 Guinea pig not_that_big
#> 9 4.190 Verbet not_that_big
#> 10 0.425 Chinchilla not_that_big
#> 11 0.101 Ground squirrel not_that_big
#> 12 0.920 Arctic ground squirrel not_that_big
#> 13 1.000 African giant pouched rat not_that_big
#> 14 0.005 Lesser short-tailed shrew not_that_big
#> 15 0.060 Star-nosed mole not_that_big
#> 16 3.500 Nine-banded armadillo not_that_big
#> 17 2.000 Tree hyrax not_that_big
#> 18 1.700 N.A. opossum not_that_big
#> 19 2547.000 Asian elephant big_mammal
#> 20 0.023 Big brown bat not_that_big
## Prepare data
df3 <- df[, c(1, 3)]
## Recode (Tidyverse)
df3 |>
mutate(mammal.cat = case_when(
body > 50 ~ "big_mammal",
body <= 50 ~ "not_that_big"
)) |>
head(20)
#> body mammal mammal.cat
#> 1 3.385 Arctic fox not_that_big
#> 2 0.480 Owl monkey not_that_big
#> 3 1.350 Mountain beaver not_that_big
#> 4 465.000 Cow big_mammal
#> 5 36.330 Grey wolf not_that_big
#> 6 27.660 Goat not_that_big
#> 7 14.830 Roe deer not_that_big
#> 8 1.040 Guinea pig not_that_big
#> 9 4.190 Verbet not_that_big
#> 10 0.425 Chinchilla not_that_big
#> 11 0.101 Ground squirrel not_that_big
#> 12 0.920 Arctic ground squirrel not_that_big
#> 13 1.000 African giant pouched rat not_that_big
#> 14 0.005 Lesser short-tailed shrew not_that_big
#> 15 0.060 Star-nosed mole not_that_big
#> 16 3.500 Nine-banded armadillo not_that_big
#> 17 2.000 Tree hyrax not_that_big
#> 18 1.700 N.A. opossum not_that_big
#> 19 2547.000 Asian elephant big_mammal
#> 20 0.023 Big brown bat not_that_big
5.3.7 Transformar variables
## Transform (Base R)
df4 <- transform(df,
brain_over_body = brain / body)
head(df4)
#> body brain mammal brain_over_body
#> 1 3.385 44.5 Arctic fox 13.1462334
#> 2 0.480 15.5 Owl monkey 32.2916667
#> 3 1.350 8.1 Mountain beaver 6.0000000
#> 4 465.000 423.0 Cow 0.9096774
#> 5 36.330 119.5 Grey wolf 3.2892926
#> 6 27.660 115.0 Goat 4.1576283
## Mutate (Tidyverse)
df |>
mutate(brain_over_body = brain / body) |>
head()
#> body brain mammal brain_over_body
#> 1 3.385 44.5 Arctic fox 13.1462334
#> 2 0.480 15.5 Owl monkey 32.2916667
#> 3 1.350 8.1 Mountain beaver 6.0000000
#> 4 465.000 423.0 Cow 0.9096774
#> 5 36.330 119.5 Grey wolf 3.2892926
#> 6 27.660 115.0 Goat 4.1576283
5.4 Unos buenos libros
Escribir el código para correr una regresión es un recreo. Lo que está más duro es entender el Gauss-Markov Theorem. Al final, el análisis estadístico no vive de la programación. La programación es apenas un servicio. La matemática -o mejor dicho, la rama de la matemática que es la estadística- ha de ser nuestra meta, siempre.
Así que permítanme recomendar unos buenos libros:
Los que son exactamente sobre R o tienen mucho código bueno y útil:
Wickham, Hadley, and Garrett Grolemund. R for data science: import, tidy, transform, visualize, and model data. O’Reilly Media, 2016.
Heumann, Christian, and Micheal Schomaker Shalabh. Introduction to statistics and data analysis. Springer, 2016.
Teetor, Paul. R cookbook: Proven recipes for data analysis, statistics, and graphics. O’Reilly Media, 2011.
Cotton, Richard. Learning R: A step-by-step function guide to data analysis. O’Reilly Media, 2013.
Grolemund, Garrett. Hands-on programming with R: Write your own functions and simulations. O’Reilly Media, 2014.
Wickham, Hadley. Advanced R. CRC Press, 2019.
Gandrud, Christopher. Reproducible research with R and R studio. Chapman and Hall/CRC, 2018.
Han, Jiawei, Jian Pei, and Hanghang Tong. Data mining: concepts and techniques. Morgan kaufmann, 2022.
Kabacoff, Robert. R in Action: Data Analysis and Graphics with R and Tidyverse. Simon and Schuster, 2022.
Los estadísticos más básicos:
Pignataro López, Adrián. Manual para el análisis político cuantitativo. Editorial UCR, 2016.
Bueno de Mesquita, Ethan, and Anthony Fowler. Thinking clearly with data: A guide to quantitative reasoning and analysis. Princeton University Press, 2021.
Imai, Kosuke. Quantitative social science: An introduction. Princeton University Press, 2018.
Bruce, Peter, Andrew Bruce, and Peter Gedeck. Practical statistics for data scientists: 50+ essential concepts using R and Python. O’Reilly Media, 2020.
Los más técnicos:
Wooldridge, Jeffrey M. Introductory econometrics: A modern approach. Cengage Learning, 2015.
Moore, Will H., and David A. Siegel. A Mathematics Course for Political and Social Research. Princeton University Press, 2013.
Gailmard, Sean. Statistical modeling and inference for social science. Cambridge University Press, 2014.
King, Gary. Unifying political methodology: The likelihood theory of statistical inference. Cambridge University Press, 1989.
Los de inferencia causal:
Angrist, Joshua D., and Jörn-Steffen Pischke. Mostly harmless econometrics: An empiricist’s companion. Princeton University Press, 2009.
Angrist, Joshua D., and Jörn-Steffen Pischke. Mastering’metrics: The path from cause to effect. Princeton University Press, 2014.
Cunningham, Scott. Causal inference: The mixtape. Yale University Press, 2021.
Glymour, Madelyn, Judea Pearl, and Nicholas P. Jewell. Causal inference in statistics: A primer. John Wiley & Sons, 2016.
Los de machine learning/data mining:
James, Gareth, Daniela Witten, Trevor Hastie, and Robert Tibshirani. An introduction to statistical learning. Springer, 2013.
Hastie, Trevor, Robert Tibshirani, Jerome H. Friedman, and Jerome H. Friedman. The elements of statistical learning: data mining, inference, and prediction. Springer, 2009.
Cichosz, Pawel. Data mining algorithms: explained using R. John Wiley & Sons, 2014.
Torgo, Luis. Data mining with R: learning with case studies. CRC Press, 2011.
Los bayesianos:
- McElreath, Richard. Statistical rethinking: A Bayesian course with examples in R and Stan. Chapman and Hall/CRC, 2020.
- Gelman, Andrew, Jennifer Hill, and Aki Vehtari. Regression and other stories. Cambridge University Press, 2020.
Los mencioné todos de pasada cuando debí destacar algunos. Si se trata de libros sobre R estrictamente, los de Hadley Wickham son siempre los mejores. Wickham tiene el don de la claridad. Busquen cualquiera de sus conferencias en YouTube y díganme si no. R for Data Science es hermoso. Lo mejor que se ha escrito sobre programación en R orientada a Data Science.
Quantitative Social Science de Kosuke Imai fue mi libro de referencia durante largo rato. Siempre que quise salir de alguna duda (básica), al libro de Imai iba a parar. La organización de ese libro no es la más deseable, pero sí es bastante completo y didáctico y encima es generoso en código. Lo acaba de destronar Thinking Clearly with Data, un libro fenomenal de Bruce Bueno de Mesquita y Anthony Fowler que, si bien no incluye código, es como recibir toda la secuencia de métodos de un programa doctoral de Political Science en los Estados Unidos. Y es lindísimo de leer. En serio. 20/10.
De los más técnicos, Introductory Econometrics de Jeffrey Wooldridge le da de comer a cualquier otro texto de econometría. A Mathematics Course for Political and Social Research es re amigable; a mí me encanta el capítulo sobre álgebra lineal y matricial y la forma tan placentera en la que aborda el tema random variables.
Hace poco descubrí que Mostly Harmless Econometrics, libro fundamental sobre inferencia causal, tiene una versión más llana: Mastering’metrics. Ambos escritos por Joshua D. Angrist y Jörn-Steffen Pischke. Empiecen por el último (es más fácil) y prepárense para que sus intereses académicos cambien por el resto de sus vidas.
En materia de Machine Learning no hay discusión posible: An introduction to statistical learning es amor. Similarmente, qué obra hermosa la de Richard McElreath, Statistical rethinking, aunque francamente la recomiendo sólo para personas medianamente avanzadas porque a esa altura la estadística bayesiana se disfruta mejor.