Teorema

# Carrega pacotes necessários
library(ggplot2)

# Carrega os dados
flu <- read.csv("flu.csv")

# Visualiza a estrutura
head(flu)
##   age
## 1   0
## 2   0
## 3   0
## 4   0
## 5   0
## 6   0
# Histograma da população
ggplot(flu, aes(x = age)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "skyblue", color = "black") +
  geom_density(color = "red", size = 1.2) +
  labs(title = "Distribuição da Idade das Mortes por Gripe (População)",
       x = "Idade", y = "Densidade") +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

# Simula 200 médias amostrais com n = 35
set.seed(123)  # Para reprodutibilidade
amostras <- replicate(200, mean(sample(flu$age, size = 35, replace = TRUE)))

media_df <- data.frame(media = amostras)

# Histograma das médias
ggplot(media_df, aes(x = media)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "lightgreen", color = "black") +
  geom_density(color = "blue", size = 1.2) +
  labs(title = "Distribuição das Médias Amostrais (n = 35)",
       x = "Média da Amostra", y = "Densidade") +
  theme_minimal()