Notas de la clase 2025-04-14

Author

Aleksander Dietrichson

Published

April 14, 2025

Datos

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
my_data <- datos_crudos |>  
  transmute(
    salario = PP08D1, 
    sexo = CH04,
    nivel_educativo = NIVEL_ED,
    edad = CH06
  ) |>
  mutate(salario = ifelse(salario<0,NA,salario)) |>
  mutate(sexo = ifelse(sexo == 1, "Hombre","Mujer"))

El uso de pipe

Es el simbolo |>

barplot(table(my_data))

my_data |>

table() |>

barplot()

my_data |>
  group_by(sexo) |>
  summarize(
    Salario_promedio = mean(salario, na.rm = TRUE)
  )
# A tibble: 2 × 2
  sexo   Salario_promedio
  <chr>             <dbl>
1 Hombre          407421.
2 Mujer           335426.

Distribucion de la variable sexo

table(my_data$sexo)

Hombre  Mujer 
 22784  24780 
my_data$sexo |>
  table()

Hombre  Mujer 
 22784  24780 

Visualizaciones

my_data$sexo |>
  table() |>
  barplot()

my_data$sexo |>
  table() |>
  pie()

my_data$salario |>
  hist()

Con ggplot

library(ggplot2)
my_data |>
  ggplot(aes(edad,salario, color = sexo))+
  geom_point()
Warning: Removed 29069 rows containing missing values or values outside the scale range
(`geom_point()`).

my_data |>
  ggplot(aes(edad,salario, color = sexo))+
  geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 29069 rows containing non-finite outside the scale range
(`stat_smooth()`).

my_data |>
  ggplot(aes(edad,salario, color = sexo))+
  geom_smooth()
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Warning: Removed 29069 rows containing non-finite outside the scale range
(`stat_smooth()`).

Tarea

  • Generar un conjunto de datos con tres o más variables partiendo de los datos del indec.

  • Usar las transformaciones que sean necesarias para poder analizar los datos.

  • Analizar con table, group_by + summarize`

    • Cual es la medida de centralización adecuada

    • Cómo medir la dispersión

  • Realizar una vialización

Lecturas

  • Capitulo 3 del libro

  • Capitulo 6 (Test de hipótesis).