Sebaran Binomial

## Parameter Simulasi

n <- 10000   # ukuran sampel
m <- 10000   # jumlah pengulangan

## Simulasi data asal (x): Binomial(15, 0.7)

data_binom <- rbinom(n, size = 15, prob = 0.7)

p1 <- ggplot(data.frame(data_binom), aes(x = data_binom)) +
  geom_histogram(aes(y = ..density..), bins = 20, fill = "skyblue", color = "black") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Asal: Binomial(15, 0.7)",
       x = "Nilai X", y = "Frekuensi")


## Sebaran rata-rata sampel: teorema limit pusat (CLT)
p2 <- ggplot(data.frame(means_binom), aes(x = means_binom)) +
  geom_histogram(aes(y = ..density..), bins = 40, fill = "blue", color = "white") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Rata-rata Sampel Binomial",
       x = "Nilai Rata-rata X (Sampel)", y = "Frekuensi")

## Gabungan dua plot

Sebaran Poisson

## Simulasi data asal (x): Poisson(4)

data_pois <- rpois(n, lambda = 4)

p3 <- ggplot(data.frame(data_pois), aes(x = data_pois)) +
  geom_histogram(aes(y = ..density..), bins = 20, fill = "skyblue", color = "black") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Asal: Poisson(4)",
       x = "Nilai X", y = "Frekuensi")


## Sebaran rata-rata sampel: teorema limit pusat (CLT)
p4 <- ggplot(data.frame(means_pois), aes(x = means_pois)) +
  geom_histogram(aes(y = ..density..), bins = 40, fill = "blue", color = "white") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Rata-rata Sampel Poisson",
       x = "Rata-rata Sampel", y = "Frekuensi")

## Gabungan dua plot

Sebaran Gamma

## Simulasi data asal (x): Gamma(0.8, 2)

data_gamma <- rgamma(n, shape = 0.8, rate = 2)


p5 <- ggplot(data.frame(data_gamma), aes(x = data_gamma)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "skyblue", color = "black") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Asal: Gamma(0.8, 2)",
       x = "Nilai X", y = "Frekuensi")


## Sebaran rata-rata sampel: teorema limit pusat (CLT)
p6 <- ggplot(data.frame(means_gamma), aes(x = means_gamma)) +
  geom_histogram(aes(y = ..density..), bins = 40, fill = "blue", color = "white") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Rata-rata Sampel Gamma",
       x = "Rata-rata Sampel", y = "Frekuensi")


## Gabungan dua plot

Sebaran Beta

## Simulasi data asal (x): Beta(30, 1)

data_beta <- rbeta(n, shape1 = 30, shape2 = 1)

p7 <- ggplot(data.frame(data_beta), aes(x = data_beta)) +
  geom_histogram(aes(y = ..density..), bins = 30, fill = "skyblue", color = "black") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Asal: Beta(30, 1)",
       x = "Nilai X", y = "Frekuensi")


## Sebaran rata-rata sampel: teorema limit pusat (CLT)
p8 <- ggplot(data.frame(means_beta), aes(x = means_beta)) +
  geom_histogram(aes(y = ..density..), bins = 40, fill = "blue", color = "white") +
  geom_density(color = "red", linewidth = 0.8) +
  labs(title = "Sebaran Rata-rata Sampel Beta",
       x = "Rata-rata Sampel", y = "Frekuensi")


## Gabungan dua plot