cat("Fiorella Michelle Sandoval Castro")
## Fiorella Michelle Sandoval Castro
library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
## 
## 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
# Datos

df <- data.frame(magnitud = quakes$mag)
n <- 150
set.seed(123)
muestra_sismos <- df %>% sample_n(n)

# Media muestral

media_muestral <- mean(muestra_sismos$magnitud)
cat("Media muestral:", round(media_muestral, 3), "\n")
## Media muestral: 4.58
# Desviación estándar muestral

sd_muestra <- sd(muestra_sismos$magnitud)

# Error estándar

error_estandar <- sd_muestra / sqrt(n)
cat("Error estandar del promedio muestral:", round(error_estandar, 3), "\n")
## Error estandar del promedio muestral: 0.032
# Nivel de confianza

confianza <- 0.90
alpha <- 1 - confianza
z <- qnorm(1 - alpha/2)

# Intervalo de confianza

IC_inferior <- media_muestral - z * error_estandar
IC_superior <- media_muestral + z * error_estandar
cat("Intervalo de confianza 90%: [", round(IC_inferior,3), ",", round(IC_superior,3), "]\n")
## Intervalo de confianza 90%: [ 4.527 , 4.633 ]
# Sismos graves

df$grave <- ifelse(df$magnitud >= 5, 1, 0)
muestra_sismos$grave <- ifelse(muestra_sismos$magnitud >= 5, 1, 0)

# Proporciones

prop_poblacional <- mean(df$grave)
prop_muestral <- mean(muestra_sismos$grave)
cat("Proporcion poblacional de sismos graves:", round(prop_poblacional,3), "\n")
## Proporcion poblacional de sismos graves: 0.198
cat("Proporcion muestral de sismos graves:", round(prop_muestral,3), "\n")
## Proporcion muestral de sismos graves: 0.2
error_estandar_prop <- sqrt(prop_muestral * (1 - prop_muestral) / n)
cat("Error estandar de la proporcion muestral:", round(error_estandar_prop,3), "\n")
## Error estandar de la proporcion muestral: 0.033