VADeaths

data("VADeaths")

VADeaths_df <- as.data.frame(VADeaths)
VADeaths_df$Age <- rownames(VADeaths_df)
VADeaths_long <- melt(VADeaths_df, id.vars = "Age")

colnames(VADeaths_long) <- c("Age", "Category", "DeathRate")

ggplot(VADeaths_long, aes(x = Age, y = DeathRate, fill = Category)) +
  geom_bar(stat = "identity", position = "stack") +
   geom_text(aes(label = DeathRate), 
            position = position_stack(vjust = 0.5), 
            color = "white", 
            size = 3.5) +
  scale_fill_manual(
    values = c(
      "Urban Male" = "#15956b",
      "Urban Female" = "#740c9e",
      "Rural Male" = "darkblue",
      "Rural Female" = "#b5102e"
    )
  ) +
  labs(
    title = "Taxas de Mortalidade por Idade e Categoria",
    x = "Grupo de Idade",
    y = "Taxa de Mortalidade",
    fill = "Categoria"
  ) +
  theme_minimal()

ClassificaçãoDoença

doenca <- c(
  "moderado", "leve", "leve", "severo", "leve", "moderado", "moderado",
  "moderado", "leve", "leve", "severo", "leve", "moderado", "moderado",
  "leve", "severo", "moderado", "moderado", "moderado", "leve"
)

freq <- table(doenca)
pct <- round(freq / sum(freq) * 100)
lbls <- paste(names(freq), pct, "%")

cores <- c("#38fe27", "#f3fe27", "#fe272e")

pie(freq,
    labels = lbls,
    col = cores,
    main = "Classificação da Doença nos Pacientes")

legend("topright", legend = names(freq), fill = cores)

Teorema

Histograma da densidade da população por idade

flu <- read.csv("https://www.dropbox.com/scl/fi/bvf1mhw33x4h6lvtty3ks/flu.csv?rlkey=e9kreupfbwrfhc3425tm3dq32&e=1&dl=1")


ggplot(flu, aes(x = age)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "gray", color = "black") +
  geom_density(color = "#f50e68", size = 1) +
  labs(
    title = "Distribuição das Idades",
    x = "Idade",
    y = "Densidade"
  ) +
  theme_minimal()

Média amostral

n <- 35     
amostra <- 200   

set.seed(123)
media <- tibble(value = replicate(amostra, mean(sample(flu$age, n, replace = TRUE))))
head(media)
## # A tibble: 6 × 1
##   value
##   <dbl>
## 1  38.9
## 2  42.9
## 3  48.5
## 4  42.5
## 5  40.3
## 6  42.1

Histograma das médias amostrais

ggplot(media, aes(x = value)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "gray", color = "black") +
  geom_density(color = "blue", size = 1) +
  labs(
    title = "Distribuição das Médias Amostrais (n = 35)",
    x = "Média Amostral",
    y = "Densidade"
  ) +
  theme_minimal()