library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(tidycensus)
library(mapview)
library(viridis)
## Loading required package: viridisLite
library(knitr)
library(leaflet)
library(stringr)
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
options(tigris_use_cache = TRUE)
install = TRUE
census_api_key("4ef23752aa9c9358bcaeaab6f3b0dd15d7030926")
## To install your API key for use in future sessions, run this function with `install = TRUE`.

Censo de los Estados Unidos

census_us_county_income <- get_acs(geography = "county", variables = "B19013_001", 
                            shift_geo = TRUE, geometry = TRUE)
## Getting data from the 2018-2022 5-year ACS
## Warning: The `shift_geo` argument is deprecated and will be removed in a future
## release. We recommend using `tigris::shift_geometry()` instead.
## Using feature geometry obtained from the albersusa package
## Please note: Alaska and Hawaii are being shifted and are not to scale.
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## Warning: The `shift_geo` argument is deprecated and will be removed in a future
## release. We recommend using `tigris::shift_geometry()` instead

Distribución poblacional del ingreso

ggplot(data = census_us_county_income) + 
  geom_sf(aes(fill = estimate), color = NA) + 
  coord_sf(datum = NA) + 
  theme_minimal() + 
  scale_fill_viridis_c()

Muestra aleatoria

sample_us_county_income <- sample_frac(tbl = census_us_county_income, size = 0.2)

Intervalos de confianza

Con base en la muestra aleatoria generada calcule un intervalo de confianza para la media poblacional de la variable ingreso, basándose en la muestra aleatoria generada (sample_us_county_income) del 90%