set.seed(123)
n <- 10
data_exp_10 <- rexp(n, rate = 1)
hist(data_exp_10, probability = TRUE, main = "Histogram of Exp(1) for n = 10",
xlab = "Value", col = "skyblue", border = "white")
lines(density(data_exp_10), col = "red", lwd = 2)
# Question 1.2
set.seed(123)
n <- 100000
data_exp_100k <- rexp(n, rate = 1)
hist(data_exp_100k, probability = TRUE, main = "Histogram of Exp(1) for n = 100k",
xlab = "Value", col = "skyblue", border = "white")
lines(density(data_exp_100k), col = "red", lwd = 2)
set.seed(123)
n<- 100000
data <- rpois(n,1)
barplot(table(data)/n, col = "blue", main = "Poison(1)", xlab = "k", ylab = "Probability")
k_val <- 0:max(data)
pois_density <- dpois(k_val, 1)
lines(k_val + 0.5, pois_density, col = "red", lwd = 2)
* Comment: The shape of the PMF for Poisson(1) is skewed to the right,
and most of the probability mass is concentrated around k=0 and k=1. The
distribution is highly skewed due to the small rate parameter λ=1.
set.seed(123)
n<- 100000
data <- rpois(n,5)
barplot_height <- barplot(table(data)/n, col = "blue", main = "Poison(5)", xlab = "k", ylab = "Probability")
k_val <- 0:max(data)
pois_density <- dpois(k_val, 5)
lines(barplot_height, pois_density, col = "red", lwd = 2)
# Set seed and parameters
set.seed(123)
n <- 100000
data1 <- rpois(n, 15)
observed_freq <- table(factor(data1, levels = 0:max(data1))) / n
barplot_heights <- barplot(observed_freq,
col = "blue",
main = "Poisson(15)",
xlab = "k",
ylab = "Probability")
# Calculate theoretical probabilities
k_value <- 0:max(data1)
pois_density <- dpois(k_value, 15)
# Add density line
lines(barplot_heights, pois_density, col = "red", lwd = 2)
Comment : The distribution becomes approximately symmetric and bell-shaped, resembling a normal distribution.
Comparison of Results (2.1 to 2.3):
set.seed(123)
norm_data_10 <- rnorm(10, mean = 1, sd = sqrt(2))
hist(norm_data_10, probability = TRUE, main = "Histogram of N(1,2), n = 10", xlab = "Value", col = "blue")
# add curve
curve(dnorm(x, mean = 1, sd = sqrt(2)), add = TRUE, col = "red", lwd = 2)
norm_data_100k <- rnorm(100000, mean = 1, sd = sqrt(2))
hist(norm_data_100k, probability = TRUE, main = "Histogram of N(1,2), n = 100k", xlab = "Value", col = "blue")
# add curve
curve(dnorm(x, mean = 1, sd = sqrt(2)), add = TRUE, col = "red", lwd = 2)